Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/domain.js

Issue 29426579: Noissue - Reimplement public suffix matching more efficiently (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created May 1, 2017, 6:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 const {getBaseDomain} = require("../lib/domain");
21
22 function testGetBaseDomain(test, domain, expected)
23 {
24 test.equal(getBaseDomain(domain), expected);
25 }
26
27 exports.domain = {
28 testGetBaseDomain(test)
29 {
30 // Based on
31 // https://github.com/publicsuffix/list/blob/master/tests/test_psl.txt
32
33 // Unlisted TLD.
34 testGetBaseDomain(test, "example", null);
35 testGetBaseDomain(test, "example.example", "example.example");
36 testGetBaseDomain(test, "b.example.example", "example.example");
37 testGetBaseDomain(test, "a.b.example.example", "example.example");
38
39 // TLD with only 1 rule.
40 testGetBaseDomain(test, "biz", null);
41 testGetBaseDomain(test, "domain.biz", "domain.biz");
42 testGetBaseDomain(test, "b.domain.biz", "domain.biz");
43 testGetBaseDomain(test, "a.b.domain.biz", "domain.biz");
44
45 // TLD with some 2-level rules.
46 testGetBaseDomain(test, "com", null);
47 testGetBaseDomain(test, "example.com", "example.com");
48 testGetBaseDomain(test, "b.example.com", "example.com");
49 testGetBaseDomain(test, "a.b.example.com", "example.com");
50 testGetBaseDomain(test, "uk.com", null);
51 testGetBaseDomain(test, "example.uk.com", "example.uk.com");
52 testGetBaseDomain(test, "b.example.uk.com", "example.uk.com");
53 testGetBaseDomain(test, "a.b.example.uk.com", "example.uk.com");
54 testGetBaseDomain(test, "test.ac", "test.ac");
55
56 // TLD with only 1 (wildcard) rule.
57 testGetBaseDomain(test, "mm", null);
58 testGetBaseDomain(test, "c.mm", null);
59 testGetBaseDomain(test, "b.c.mm", "b.c.mm");
60 testGetBaseDomain(test, "a.b.c.mm", "b.c.mm");
61
62 // More complex TLD.
63 testGetBaseDomain(test, "jp", null);
64 testGetBaseDomain(test, "test.jp", "test.jp");
65 testGetBaseDomain(test, "www.test.jp", "test.jp");
66 testGetBaseDomain(test, "ac.jp", null);
67 testGetBaseDomain(test, "test.ac.jp", "test.ac.jp");
68 testGetBaseDomain(test, "www.test.ac.jp", "test.ac.jp");
69 testGetBaseDomain(test, "kyoto.jp", null);
70 testGetBaseDomain(test, "test.kyoto.jp", "test.kyoto.jp");
71 testGetBaseDomain(test, "ide.kyoto.jp", null);
72 testGetBaseDomain(test, "b.ide.kyoto.jp", "b.ide.kyoto.jp");
73 testGetBaseDomain(test, "a.b.ide.kyoto.jp", "b.ide.kyoto.jp");
74 testGetBaseDomain(test, "c.kobe.jp", null);
75 testGetBaseDomain(test, "b.c.kobe.jp", "b.c.kobe.jp");
76 testGetBaseDomain(test, "a.b.c.kobe.jp", "b.c.kobe.jp");
77 testGetBaseDomain(test, "city.kobe.jp", "city.kobe.jp");
78 testGetBaseDomain(test, "www.city.kobe.jp", "city.kobe.jp");
79
80 // TLD with a wildcard rule and exceptions.
81 testGetBaseDomain(test, "ck", null);
82 testGetBaseDomain(test, "test.ck", null);
83 testGetBaseDomain(test, "b.test.ck", "b.test.ck");
84 testGetBaseDomain(test, "a.b.test.ck", "b.test.ck");
85 testGetBaseDomain(test, "www.ck", "www.ck");
86 testGetBaseDomain(test, "www.www.ck", "www.ck");
87
88 // US K12.
89 testGetBaseDomain(test, "us", null);
90 testGetBaseDomain(test, "test.us", "test.us");
91 testGetBaseDomain(test, "www.test.us", "test.us");
92 testGetBaseDomain(test, "ak.us", null);
93 testGetBaseDomain(test, "test.ak.us", "test.ak.us");
94 testGetBaseDomain(test, "www.test.ak.us", "test.ak.us");
95 testGetBaseDomain(test, "k12.ak.us", null);
96 testGetBaseDomain(test, "test.k12.ak.us", "test.k12.ak.us");
97 testGetBaseDomain(test, "www.test.k12.ak.us", "test.k12.ak.us");
98
99 // IDN labels, punycoded.
100 testGetBaseDomain(test, "xn--85x722f.com.cn", "xn--85x722f.com.cn");
101 testGetBaseDomain(test, "xn--85x722f.xn--55qx5d.cn",
102 "xn--85x722f.xn--55qx5d.cn");
103 testGetBaseDomain(test, "www.xn--85x722f.xn--55qx5d.cn",
104 "xn--85x722f.xn--55qx5d.cn");
105 testGetBaseDomain(test, "shishi.xn--55qx5d.cn", "shishi.xn--55qx5d.cn");
106 testGetBaseDomain(test, "xn--55qx5d.cn", null);
107 testGetBaseDomain(test, "xn--85x722f.xn--fiqs8s",
108 "xn--85x722f.xn--fiqs8s");
109 testGetBaseDomain(test, "www.xn--85x722f.xn--fiqs8s",
110 "xn--85x722f.xn--fiqs8s");
111 testGetBaseDomain(test, "shishi.xn--fiqs8s", "shishi.xn--fiqs8s");
112 testGetBaseDomain(test, "xn--fiqs8s", null);
113
114 test.done();
115 }
116 };
OLDNEW
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld