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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/domain.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/domain.js
@@ -0,0 +1,116 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2017 eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+const {getBaseDomain} = require("../lib/domain");
+
+function testGetBaseDomain(test, domain, expected)
+{
+ test.equal(getBaseDomain(domain), expected);
+}
+
+exports.domain = {
+ testGetBaseDomain(test)
+ {
+ // Based on
+ // https://github.com/publicsuffix/list/blob/master/tests/test_psl.txt
+
+ // Unlisted TLD.
+ testGetBaseDomain(test, "example", null);
+ testGetBaseDomain(test, "example.example", "example.example");
+ testGetBaseDomain(test, "b.example.example", "example.example");
+ testGetBaseDomain(test, "a.b.example.example", "example.example");
+
+ // TLD with only 1 rule.
+ testGetBaseDomain(test, "biz", null);
+ testGetBaseDomain(test, "domain.biz", "domain.biz");
+ testGetBaseDomain(test, "b.domain.biz", "domain.biz");
+ testGetBaseDomain(test, "a.b.domain.biz", "domain.biz");
+
+ // TLD with some 2-level rules.
+ testGetBaseDomain(test, "com", null);
+ testGetBaseDomain(test, "example.com", "example.com");
+ testGetBaseDomain(test, "b.example.com", "example.com");
+ testGetBaseDomain(test, "a.b.example.com", "example.com");
+ testGetBaseDomain(test, "uk.com", null);
+ testGetBaseDomain(test, "example.uk.com", "example.uk.com");
+ testGetBaseDomain(test, "b.example.uk.com", "example.uk.com");
+ testGetBaseDomain(test, "a.b.example.uk.com", "example.uk.com");
+ testGetBaseDomain(test, "test.ac", "test.ac");
+
+ // TLD with only 1 (wildcard) rule.
+ testGetBaseDomain(test, "mm", null);
+ testGetBaseDomain(test, "c.mm", null);
+ testGetBaseDomain(test, "b.c.mm", "b.c.mm");
+ testGetBaseDomain(test, "a.b.c.mm", "b.c.mm");
+
+ // More complex TLD.
+ testGetBaseDomain(test, "jp", null);
+ testGetBaseDomain(test, "test.jp", "test.jp");
+ testGetBaseDomain(test, "www.test.jp", "test.jp");
+ testGetBaseDomain(test, "ac.jp", null);
+ testGetBaseDomain(test, "test.ac.jp", "test.ac.jp");
+ testGetBaseDomain(test, "www.test.ac.jp", "test.ac.jp");
+ testGetBaseDomain(test, "kyoto.jp", null);
+ testGetBaseDomain(test, "test.kyoto.jp", "test.kyoto.jp");
+ testGetBaseDomain(test, "ide.kyoto.jp", null);
+ testGetBaseDomain(test, "b.ide.kyoto.jp", "b.ide.kyoto.jp");
+ testGetBaseDomain(test, "a.b.ide.kyoto.jp", "b.ide.kyoto.jp");
+ testGetBaseDomain(test, "c.kobe.jp", null);
+ testGetBaseDomain(test, "b.c.kobe.jp", "b.c.kobe.jp");
+ testGetBaseDomain(test, "a.b.c.kobe.jp", "b.c.kobe.jp");
+ testGetBaseDomain(test, "city.kobe.jp", "city.kobe.jp");
+ testGetBaseDomain(test, "www.city.kobe.jp", "city.kobe.jp");
+
+ // TLD with a wildcard rule and exceptions.
+ testGetBaseDomain(test, "ck", null);
+ testGetBaseDomain(test, "test.ck", null);
+ testGetBaseDomain(test, "b.test.ck", "b.test.ck");
+ testGetBaseDomain(test, "a.b.test.ck", "b.test.ck");
+ testGetBaseDomain(test, "www.ck", "www.ck");
+ testGetBaseDomain(test, "www.www.ck", "www.ck");
+
+ // US K12.
+ testGetBaseDomain(test, "us", null);
+ testGetBaseDomain(test, "test.us", "test.us");
+ testGetBaseDomain(test, "www.test.us", "test.us");
+ testGetBaseDomain(test, "ak.us", null);
+ testGetBaseDomain(test, "test.ak.us", "test.ak.us");
+ testGetBaseDomain(test, "www.test.ak.us", "test.ak.us");
+ testGetBaseDomain(test, "k12.ak.us", null);
+ testGetBaseDomain(test, "test.k12.ak.us", "test.k12.ak.us");
+ testGetBaseDomain(test, "www.test.k12.ak.us", "test.k12.ak.us");
+
+ // IDN labels, punycoded.
+ testGetBaseDomain(test, "xn--85x722f.com.cn", "xn--85x722f.com.cn");
+ testGetBaseDomain(test, "xn--85x722f.xn--55qx5d.cn",
+ "xn--85x722f.xn--55qx5d.cn");
+ testGetBaseDomain(test, "www.xn--85x722f.xn--55qx5d.cn",
+ "xn--85x722f.xn--55qx5d.cn");
+ testGetBaseDomain(test, "shishi.xn--55qx5d.cn", "shishi.xn--55qx5d.cn");
+ testGetBaseDomain(test, "xn--55qx5d.cn", null);
+ testGetBaseDomain(test, "xn--85x722f.xn--fiqs8s",
+ "xn--85x722f.xn--fiqs8s");
+ testGetBaseDomain(test, "www.xn--85x722f.xn--fiqs8s",
+ "xn--85x722f.xn--fiqs8s");
+ testGetBaseDomain(test, "shishi.xn--fiqs8s", "shishi.xn--fiqs8s");
+ testGetBaseDomain(test, "xn--fiqs8s", null);
+
+ test.done();
+ }
+};
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld