Browse Source

Update Tests & Make TypeScript happy

SukkaW 1 year ago
parent
commit
d1041f0e59

+ 1 - 1
Build/lib/fetch-text-by-line.bench.ts

@@ -7,7 +7,7 @@ import { SOURCE_DIR } from '../constants/dir';
 
 const file = path.join(SOURCE_DIR, 'domainset/cdn.conf');
 
-group('read file by line', () => {
+group(() => {
   bench('readFileByLine', () => processLineFromReadline(readFileByLine(file)));
   bench('fsp.readFile', () => fsp.readFile(file, 'utf-8').then((content) => content.split('\n').filter(processLine)));
 });

+ 1 - 1
Build/lib/parse-filter.test.ts

@@ -11,7 +11,7 @@ describe('parse', () => {
   const MUTABLE_PARSE_LINE_RESULT: [string, ParseType] = ['', 1000];
 
   it('||top.mail.ru^$badfilter', () => {
-    console.log(parse('||top.mail.ru^$badfilter', MUTABLE_PARSE_LINE_RESULT));
+    console.log(parse('||top.mail.ru^$badfilter', MUTABLE_PARSE_LINE_RESULT, false));
   });
 });
 

+ 2 - 0
Build/lib/rules/ip.ts

@@ -15,6 +15,8 @@ export class IPListOutput extends RuleOutput<Preprocessed> {
     super(span, id);
   }
 
+  mitmSgmodule = undefined;
+
   protected preprocess() {
     const results: string[] = [];
     appendArrayInPlace(

+ 4 - 4
Build/lib/set-add-from-array.bench.ts

@@ -6,16 +6,16 @@ import { bench, group, run } from 'mitata';
 (async () => {
   const data = await processLineFromReadline(await fetchRemoteTextByLine('https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt'));
 
-  group('setAddFromArray', () => {
-    bench('run', () => {
+  group(() => {
+    bench('setAddFromArray', () => {
       const set = new Set(['1', '2', '1', '3', 'skk.moe']);
       for (let i = 0, len = data.length; i < len; i++) {
         set.add(data[i]);
       }
     });
   });
-  group('setAddFromArray', () => {
-    bench('run', () => {
+  group(() => {
+    bench('', () => {
       const set = new Set(['1', '2', '1', '3', 'skk.moe']);
       // eslint-disable-next-line @typescript-eslint/unbound-method -- thisArg is passed
       data.forEach(set.add, set);

+ 2 - 2
Build/lib/stable-sort-domain.bench.ts

@@ -7,8 +7,8 @@ import { bench, group, run } from 'mitata';
 (async () => {
   const data = await processLineFromReadline(await fetchRemoteTextByLine('https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt'));
 
-  group('sortDomains', () => {
-    bench('run', () => sortDomains(data));
+  group(() => {
+    bench('sortDomains', () => sortDomains(data));
   });
 
   run();

+ 1 - 1
Build/lib/tldts.bench.ts

@@ -18,7 +18,7 @@ import * as tldtsExperimental from 'tldts-experimental';
   };
 
   (['getDomain', 'getPublicSuffix', 'getSubdomain', 'parse'] as const).forEach(methodName => {
-    group(methodName, () => {
+    group(() => {
       bench('tldts', () => {
         for (let i = 0, len = data.length; i < len; i++) {
           tldts[methodName](data[i], tldtsOpt);

+ 20 - 3
Build/lib/trie.test.ts

@@ -35,7 +35,7 @@ describe('hostname to tokens', () => {
 
 describe('Trie', () => {
   it('should be possible to add domains to a Trie.', () => {
-    const trie = createTrie();
+    const trie = createTrie(null, false);
 
     trie.add('a.skk.moe');
     trie.add('skk.moe');
@@ -52,7 +52,7 @@ describe('Trie', () => {
   });
 
   it('adding the same item several times should not increase size.', () => {
-    const trie = createTrie();
+    const trie = createTrie(null, false);
 
     trie.add('skk.moe');
     trie.add('blog.skk.moe');
@@ -63,7 +63,7 @@ describe('Trie', () => {
   });
 
   it('should be possible to set the null sequence.', () => {
-    let trie = createTrie();
+    let trie = createTrie(null, false);
 
     trie.add('');
     expect(trie.has('')).to.equal(true);
@@ -123,6 +123,23 @@ describe('Trie', () => {
     expect(trie.find('')).to.deep.equal(['example.org', 'example.com', 'cdn.example.com', 'blog.example.com']);
   });
 
+  it('should be possible to retrieve items matching the given prefix even with a smol trie.', () => {
+    const trie = createTrie(null, true);
+
+    trie.add('.example.com');
+    trie.add('example.com');
+    trie.add('blog.example.com');
+    trie.add('cdn.example.com');
+    trie.add('example.org');
+
+    expect(trie.find('example.com')).to.deep.equal(['.example.com']);
+    expect(trie.find('com')).to.deep.equal(['.example.com']);
+    expect(trie.find('.example.com')).to.deep.equal(['.example.com']);
+    expect(trie.find('org')).to.deep.equal(['example.org']);
+    expect(trie.find('example.net')).to.deep.equal([]);
+    expect(trie.find('')).to.deep.equal(['example.org', '.example.com']);
+  });
+
   it('should be possible to create a trie from an arbitrary iterable.', () => {
     let trie = createTrie(['skk.moe', 'blog.skk.moe']);