Update Tests & Make TypeScript happy

This commit is contained in:
SukkaW
2024-10-02 21:33:59 +08:00
parent 9735d05956
commit d1041f0e59
7 changed files with 31 additions and 12 deletions

View File

@@ -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']);