|
@@ -1,8 +1,5 @@
|
|
|
-require('chai').should();
|
|
|
|
|
-
|
|
|
|
|
-const createTrie = require('./trie');
|
|
|
|
|
-const assert = require('assert');
|
|
|
|
|
-const { describe, it } = require('mocha');
|
|
|
|
|
|
|
+import createTrie from './trie';
|
|
|
|
|
+import { describe, expect, it } from 'bun:test';
|
|
|
|
|
|
|
|
describe('Trie', () => {
|
|
describe('Trie', () => {
|
|
|
it('should be possible to add items to a Trie.', () => {
|
|
it('should be possible to add items to a Trie.', () => {
|
|
@@ -12,13 +9,13 @@ describe('Trie', () => {
|
|
|
trie.add('ukka');
|
|
trie.add('ukka');
|
|
|
trie.add('akku');
|
|
trie.add('akku');
|
|
|
|
|
|
|
|
- trie.size.should.eq(3);
|
|
|
|
|
- trie.has('sukka').should.eq(true);
|
|
|
|
|
- trie.has('ukka').should.eq(true);
|
|
|
|
|
- trie.has('akku').should.eq(true);
|
|
|
|
|
- trie.has('noc').should.eq(false);
|
|
|
|
|
- trie.has('suk').should.eq(false);
|
|
|
|
|
- trie.has('sukkaw').should.eq(false);
|
|
|
|
|
|
|
+ expect(trie.size).toBe(3);
|
|
|
|
|
+ expect(trie.has('sukka')).toBeTrue();
|
|
|
|
|
+ expect(trie.has('ukka')).toBeTrue();
|
|
|
|
|
+ expect(trie.has('akku')).toBeTrue();
|
|
|
|
|
+ expect(trie.has('noc')).toBeFalse();
|
|
|
|
|
+ expect(trie.has('suk')).toBeFalse();
|
|
|
|
|
+ expect(trie.has('sukkaw')).toBeFalse();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('adding the same item several times should not increase size.', () => {
|
|
it('adding the same item several times should not increase size.', () => {
|
|
@@ -28,15 +25,15 @@ describe('Trie', () => {
|
|
|
trie.add('erat');
|
|
trie.add('erat');
|
|
|
trie.add('rat');
|
|
trie.add('rat');
|
|
|
|
|
|
|
|
- assert.strictEqual(trie.size, 2);
|
|
|
|
|
- assert.strictEqual(trie.has('rat'), true);
|
|
|
|
|
|
|
+ expect(trie.size).toBe(2);
|
|
|
|
|
+ expect(trie.has('rat')).toBeTrue();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should be possible to set the null sequence.', () => {
|
|
it('should be possible to set the null sequence.', () => {
|
|
|
const trie = createTrie();
|
|
const trie = createTrie();
|
|
|
|
|
|
|
|
trie.add('');
|
|
trie.add('');
|
|
|
- trie.has('').should.eq(true);
|
|
|
|
|
|
|
+ expect(trie.has('')).toBeTrue();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should be possible to delete items.', () => {
|
|
it('should be possible to delete items.', () => {
|
|
@@ -46,20 +43,20 @@ describe('Trie', () => {
|
|
|
trie.add('rate');
|
|
trie.add('rate');
|
|
|
trie.add('tar');
|
|
trie.add('tar');
|
|
|
|
|
|
|
|
- assert.strictEqual(trie.delete(''), false);
|
|
|
|
|
- trie.delete('').should.eq(false);
|
|
|
|
|
- trie.delete('hello').should.eq(false);
|
|
|
|
|
|
|
+ expect(trie.delete('')).toBeFalse();
|
|
|
|
|
+ expect(trie.delete('')).toBeFalse();
|
|
|
|
|
+ expect(trie.delete('hello')).toBeFalse();
|
|
|
|
|
|
|
|
- trie.delete('rat').should.eq(true);
|
|
|
|
|
- trie.has('rat').should.eq(false);
|
|
|
|
|
- trie.has('rate').should.eq(true);
|
|
|
|
|
|
|
+ expect(trie.delete('rat')).toBeTrue();
|
|
|
|
|
+ expect(trie.has('rat')).toBeFalse();
|
|
|
|
|
+ expect(trie.has('rate')).toBeTrue();
|
|
|
|
|
|
|
|
- trie.size.should.eq(2);
|
|
|
|
|
|
|
+ expect(trie.size).toBe(2);
|
|
|
|
|
|
|
|
- assert.strictEqual(trie.delete('rate'), true);
|
|
|
|
|
- assert.strictEqual(trie.size, 1);
|
|
|
|
|
- assert.strictEqual(trie.delete('tar'), true);
|
|
|
|
|
- assert.strictEqual(trie.size, 0);
|
|
|
|
|
|
|
+ expect(trie.delete('rate')).toBeTrue();
|
|
|
|
|
+ expect(trie.size).toBe(1);
|
|
|
|
|
+ expect(trie.delete('tar')).toBe(true);
|
|
|
|
|
+ expect(trie.size).toBe(0);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should be possible to check the existence of a sequence in the Trie.', () => {
|
|
it('should be possible to check the existence of a sequence in the Trie.', () => {
|
|
@@ -67,9 +64,9 @@ describe('Trie', () => {
|
|
|
|
|
|
|
|
trie.add('romanesque');
|
|
trie.add('romanesque');
|
|
|
|
|
|
|
|
- assert.strictEqual(trie.has('romanesque'), true);
|
|
|
|
|
- assert.strictEqual(trie.has('roman'), false);
|
|
|
|
|
- assert.strictEqual(trie.has(''), false);
|
|
|
|
|
|
|
+ expect(trie.has('romanesque')).toBe(true);
|
|
|
|
|
+ expect(trie.has('roman')).toBe(false);
|
|
|
|
|
+ expect(trie.has('')).toBe(false);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should be possible to retrieve items matching the given prefix.', () => {
|
|
it('should be possible to retrieve items matching the given prefix.', () => {
|
|
@@ -80,12 +77,12 @@ describe('Trie', () => {
|
|
|
trie.add('sesqueroman');
|
|
trie.add('sesqueroman');
|
|
|
trie.add('greek');
|
|
trie.add('greek');
|
|
|
|
|
|
|
|
- assert.deepStrictEqual(trie.find('roman'), ['roman', 'esqueroman', 'sesqueroman']);
|
|
|
|
|
- assert.deepStrictEqual(trie.find('man'), ['roman', 'esqueroman', 'sesqueroman']);
|
|
|
|
|
- assert.deepStrictEqual(trie.find('esqueroman'), ['esqueroman', 'sesqueroman']);
|
|
|
|
|
- assert.deepStrictEqual(trie.find('eek'), ['greek']);
|
|
|
|
|
- assert.deepStrictEqual(trie.find('hello'), []);
|
|
|
|
|
- assert.deepStrictEqual(trie.find(''), ['greek', 'roman', 'esqueroman', 'sesqueroman']);
|
|
|
|
|
|
|
+ expect(trie.find('roman')).toEqual(['roman', 'esqueroman', 'sesqueroman']);
|
|
|
|
|
+ expect(trie.find('man')).toEqual(['roman', 'esqueroman', 'sesqueroman']);
|
|
|
|
|
+ expect(trie.find('esqueroman')).toEqual(['esqueroman', 'sesqueroman']);
|
|
|
|
|
+ expect(trie.find('eek')).toEqual(['greek']);
|
|
|
|
|
+ expect(trie.find('hello')).toEqual([]);
|
|
|
|
|
+ expect(trie.find('')).toEqual(['greek', 'roman', 'esqueroman', 'sesqueroman']);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// it('should work with custom tokens.', () => {
|
|
// it('should work with custom tokens.', () => {
|
|
@@ -146,8 +143,8 @@ describe('Trie', () => {
|
|
|
|
|
|
|
|
const trie = createTrie(words);
|
|
const trie = createTrie(words);
|
|
|
|
|
|
|
|
- assert.strictEqual(trie.size, 2);
|
|
|
|
|
- assert.deepStrictEqual(trie.has('roman'), true);
|
|
|
|
|
|
|
+ expect(trie.size).toBe(2);
|
|
|
|
|
+ expect(trie.has('roman')).toBe(true);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -155,20 +152,20 @@ describe('surge domainset dedupe', () => {
|
|
|
it('should not remove same entry', () => {
|
|
it('should not remove same entry', () => {
|
|
|
const trie = createTrie(['.skk.moe', 'noc.one']);
|
|
const trie = createTrie(['.skk.moe', 'noc.one']);
|
|
|
|
|
|
|
|
- trie.find('.skk.moe').should.eql(['.skk.moe']);
|
|
|
|
|
- trie.find('noc.one').should.eql(['noc.one']);
|
|
|
|
|
|
|
+ expect(trie.find('.skk.moe')).toStrictEqual(['.skk.moe']);
|
|
|
|
|
+ expect(trie.find('noc.one')).toStrictEqual(['noc.one']);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should remove subdomain', () => {
|
|
it('should remove subdomain', () => {
|
|
|
const trie = createTrie(['www.noc.one', 'www.sukkaw.com', 'blog.skk.moe', 'image.cdn.skk.moe', 'cdn.sukkaw.net']);
|
|
const trie = createTrie(['www.noc.one', 'www.sukkaw.com', 'blog.skk.moe', 'image.cdn.skk.moe', 'cdn.sukkaw.net']);
|
|
|
- // trie.find('noc.one').should.eql(['www.noc.one']);
|
|
|
|
|
- trie.find('.skk.moe').should.eql(['image.cdn.skk.moe', 'blog.skk.moe']);
|
|
|
|
|
- // trie.find('sukkaw.net').should.eql(['cdn.sukkaw.net']);
|
|
|
|
|
- trie.find('.sukkaw.com').should.eql(['www.sukkaw.com']);
|
|
|
|
|
|
|
+ // trie.find('noc.one').toBe(['www.noc.one']);
|
|
|
|
|
+ expect(trie.find('.skk.moe')).toStrictEqual(['image.cdn.skk.moe', 'blog.skk.moe']);
|
|
|
|
|
+ // trie.find('sukkaw.net').toBe(['cdn.sukkaw.net']);
|
|
|
|
|
+ expect(trie.find('.sukkaw.com')).toStrictEqual(['www.sukkaw.com']);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should not remove non-subdomain', () => {
|
|
it('should not remove non-subdomain', () => {
|
|
|
const trie = createTrie(['skk.moe', 'sukkaskk.moe']);
|
|
const trie = createTrie(['skk.moe', 'sukkaskk.moe']);
|
|
|
- trie.find('.skk.moe').should.eql([]);
|
|
|
|
|
|
|
+ expect(trie.find('.skk.moe')).toStrictEqual([]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|