mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Chore: rewrite trie and sorter test in bun:test
This commit is contained in:
parent
4cda4df451
commit
6962c47782
@ -6,12 +6,20 @@ export const HOSTS = [
|
||||
['https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts', false],
|
||||
['https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', false],
|
||||
// Curben's UrlHaus Malicious URL Blocklist
|
||||
// 'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-agh-online.txt',
|
||||
// 'https://urlhaus-filter.pages.dev/urlhaus-filter-agh-online.txt',
|
||||
// 'https://ublockorigin.github.io/uAssets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt',
|
||||
['https://curbengh.github.io/urlhaus-filter/urlhaus-filter-hosts.txt', true, true],
|
||||
// Curben's Phishing URL Blocklist
|
||||
// 'https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt'
|
||||
// 'https://phishing-filter.pages.dev/phishing-filter-agh.txt'
|
||||
['https://curbengh.github.io/phishing-filter/phishing-filter-hosts.txt', true, true],
|
||||
// Curben's PUP Domains Blocklist
|
||||
// 'https://curbengh.github.io/pup-filter/pup-filter-agh.txt'
|
||||
// 'https://pup-filter.pages.dev/pup-filter-agh.txt'
|
||||
['https://curbengh.github.io/pup-filter/pup-filter-hosts.txt', true, true],
|
||||
// BarbBlock
|
||||
// 'https://paulgb.github.io/BarbBlock/blacklists/ublock-origin.txt',
|
||||
['https://paulgb.github.io/BarbBlock/blacklists/hosts-file.txt', true, true]
|
||||
] as const;
|
||||
|
||||
@ -110,34 +118,6 @@ export const ADGUARD_FILTERS = [
|
||||
'https://easylist-downloads.adblockplus.org/easylistgermany.txt'
|
||||
]
|
||||
],
|
||||
// Curben's UrlHaus Malicious URL Blocklist
|
||||
// [
|
||||
// 'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-agh-online.txt',
|
||||
// [
|
||||
// 'https://urlhaus-filter.pages.dev/urlhaus-filter-agh-online.txt',
|
||||
// // Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// // 'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-agh-online.txt',
|
||||
// 'https://ublockorigin.github.io/uAssets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt',
|
||||
// ]
|
||||
// ],
|
||||
// Curben's Phishing URL Blocklist
|
||||
// [
|
||||
// 'https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt',
|
||||
// [
|
||||
// 'https://phishing-filter.pages.dev/phishing-filter-agh.txt'
|
||||
// // Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// // 'https://malware-filter.gitlab.io/malware-filter/phishing-filter-agh.txt'
|
||||
// ]
|
||||
// ],
|
||||
// Curben's PUP Domains Blocklist
|
||||
// [
|
||||
// 'https://curbengh.github.io/pup-filter/pup-filter-agh.txt',
|
||||
// [
|
||||
// 'https://pup-filter.pages.dev/pup-filter-agh.txt'
|
||||
// // Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// // 'https://malware-filter.gitlab.io/malware-filter/pup-filter-agh.txt'
|
||||
// ]
|
||||
// ],
|
||||
// GameConsoleAdblockList
|
||||
'https://raw.githubusercontent.com/DandelionSprout/adfilt/master/GameConsoleAdblockList.txt',
|
||||
// PiHoleBlocklist
|
||||
@ -149,8 +129,6 @@ export const ADGUARD_FILTERS = [
|
||||
],
|
||||
// Spam404
|
||||
'https://raw.githubusercontent.com/Spam404/lists/master/adblock-list.txt',
|
||||
// BarbBlock
|
||||
// 'https://paulgb.github.io/BarbBlock/blacklists/ublock-origin.txt',
|
||||
// Brave First Party & First Party CNAME
|
||||
'https://raw.githubusercontent.com/brave/adblock-lists/master/brave-lists/brave-firstparty.txt'
|
||||
] as const;
|
||||
@ -167,7 +145,6 @@ export const PREDEFINED_WHITELIST = [
|
||||
'mcastprefix',
|
||||
'skk.moe',
|
||||
'analytics.google.com',
|
||||
'msa.cdn.mediaset.net', // Added manually using DOMAIN-KEYWORDS
|
||||
'cloud.answerhub.com',
|
||||
'ae01.alicdn.com',
|
||||
'whoami.akamai.net',
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
const domainSorter = require('./stable-sort-domain');
|
||||
const chai = require('chai');
|
||||
const { describe, it } = require('mocha');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('stable-sort-domain', () => {
|
||||
it('.ks.cn, .tag.unclaimedproperty.ks.gov', () => {
|
||||
domainSorter('.ks.cn', '.tag.unclaimedproperty.ks.gov').should.eql(-1);
|
||||
});
|
||||
});
|
||||
8
Build/lib/stable-sort-domain.test.ts
Normal file
8
Build/lib/stable-sort-domain.test.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import domainSorter from './stable-sort-domain';
|
||||
import { describe, it, expect } from 'bun:test';
|
||||
|
||||
describe('stable-sort-domain', () => {
|
||||
it('.ks.cn, .tag.unclaimedproperty.ks.gov', () => {
|
||||
expect(domainSorter('.ks.cn', '.tag.unclaimedproperty.ks.gov')).toBe(-1);
|
||||
});
|
||||
});
|
||||
@ -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', () => {
|
||||
it('should be possible to add items to a Trie.', () => {
|
||||
@ -12,13 +9,13 @@ describe('Trie', () => {
|
||||
trie.add('ukka');
|
||||
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.', () => {
|
||||
@ -28,15 +25,15 @@ describe('Trie', () => {
|
||||
trie.add('erat');
|
||||
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.', () => {
|
||||
const trie = createTrie();
|
||||
|
||||
trie.add('');
|
||||
trie.has('').should.eq(true);
|
||||
expect(trie.has('')).toBeTrue();
|
||||
});
|
||||
|
||||
it('should be possible to delete items.', () => {
|
||||
@ -46,20 +43,20 @@ describe('Trie', () => {
|
||||
trie.add('rate');
|
||||
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.', () => {
|
||||
@ -67,9 +64,9 @@ describe('Trie', () => {
|
||||
|
||||
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.', () => {
|
||||
@ -80,12 +77,12 @@ describe('Trie', () => {
|
||||
trie.add('sesqueroman');
|
||||
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.', () => {
|
||||
@ -146,8 +143,8 @@ describe('Trie', () => {
|
||||
|
||||
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', () => {
|
||||
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', () => {
|
||||
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', () => {
|
||||
const trie = createTrie(['skk.moe', 'sukkaskk.moe']);
|
||||
trie.find('.skk.moe').should.eql([]);
|
||||
expect(trie.find('.skk.moe')).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user