mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Feat: trie now supports whitelist method
This commit is contained in:
@@ -144,8 +144,6 @@ describe('smol tree', () => {
|
||||
'.blog.sub.example.com', 'sub.example.com', 'cdn.sub.example.com', '.sub.example.com'
|
||||
], true, true);
|
||||
|
||||
console.log(trie);
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'.sub.example.com',
|
||||
'cdn.noc.one', 'www.noc.one',
|
||||
@@ -153,13 +151,11 @@ describe('smol tree', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it.only('should create simple tree - 2', () => {
|
||||
it('should create simple tree - 2', () => {
|
||||
const trie = createTrie([
|
||||
'.skk.moe', 'blog.skk.moe', '.cdn.skk.moe', 'skk.moe'
|
||||
], true, true);
|
||||
|
||||
console.log({ trie });
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'.skk.moe'
|
||||
]);
|
||||
@@ -170,8 +166,6 @@ describe('smol tree', () => {
|
||||
'.blog.sub.example.com', 'cdn.sub.example.com', '.sub.example.com'
|
||||
], true, true);
|
||||
|
||||
console.log(trie);
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'.sub.example.com'
|
||||
]);
|
||||
@@ -197,4 +191,54 @@ describe('smol tree', () => {
|
||||
'act.commercial.shouji.360.cn'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should dedupe subdomain properly', () => {
|
||||
const trie = createTrie([
|
||||
'skk.moe',
|
||||
'anotherskk.moe',
|
||||
'blog.anotherskk.moe',
|
||||
'blog.skk.moe'
|
||||
], true, true);
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'anotherskk.moe',
|
||||
'blog.anotherskk.moe',
|
||||
'skk.moe',
|
||||
'blog.skk.moe'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should efficiently whitelist domains', () => {
|
||||
const trie = createTrie([
|
||||
'skk.moe',
|
||||
'anotherskk.moe',
|
||||
'blog.anotherskk.moe',
|
||||
'blog.skk.moe'
|
||||
], true, true);
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'anotherskk.moe',
|
||||
'blog.anotherskk.moe',
|
||||
'skk.moe',
|
||||
'blog.skk.moe'
|
||||
]);
|
||||
|
||||
trie.whitelist('.skk.moe');
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'anotherskk.moe',
|
||||
'blog.anotherskk.moe'
|
||||
]);
|
||||
|
||||
trie.whitelist('anotherskk.moe');
|
||||
|
||||
expect(trie.dump()).toStrictEqual([
|
||||
'blog.anotherskk.moe'
|
||||
]);
|
||||
|
||||
trie.add('anotherskk.moe');
|
||||
trie.whitelist('.anotherskk.moe');
|
||||
|
||||
expect(trie.dump()).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user