parse-domain 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/build/tries/icann.complete.json +1 -1
- package/build/tries/icann.light.json +1 -1
- package/build/tries/meta.json +1 -1
- package/build/tries/private.complete.json +1 -1
- package/lib/parseDomain.js +18 -36
- package/lib/trie/characters.js +16 -0
- package/lib/trie/lookUp.js +33 -0
- package/lib/trie/nodes.js +40 -0
- package/lib/trie/parse.js +64 -0
- package/lib/{tries → trie}/parsePubSuffixList.js +0 -0
- package/lib/{tries → trie}/serializeTrie.js +6 -6
- package/lists/icann.complete.js +2 -2
- package/lists/icann.light.js +2 -2
- package/lists/private.complete.js +2 -2
- package/package.json +1 -1
- package/scripts/build-tries.js +3 -3
- package/test/parseDomain.test.js +124 -1
- package/test/snapshots.test.js +2 -23
- package/test/trie/lookUp.test.js +99 -0
- package/test/trie/nodes.test.js +22 -0
- package/test/trie/parse.test.js +143 -0
- package/test/{tries → trie}/parsePubSuffixList.test.js +1 -1
- package/test/{tries → trie}/serializeTrie.test.js +1 -1
- package/build/.DS_Store +0 -0
- package/lib/tries/lookUp.js +0 -40
- package/lib/tries/parseTrie.js +0 -62
- package/lib/tries/separators.js +0 -12
- package/test/tries/lookUp.test.js +0 -116
- package/test/tries/parseTrie.test.js +0 -162
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const chai = require("chai");
|
|
4
|
+
const parse = require("../../lib/trie/parse");
|
|
5
|
+
|
|
6
|
+
const expect = chai.expect;
|
|
7
|
+
|
|
8
|
+
describe("parse()", () => {
|
|
9
|
+
describe("when called with ''", () => {
|
|
10
|
+
it("returns a node with null as domain and no children", () => {
|
|
11
|
+
const root = parse("");
|
|
12
|
+
|
|
13
|
+
expect(root.domain).to.equal(null);
|
|
14
|
+
expect(root.children.size).to.equal(0);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe("when called with 'a'", () => {
|
|
18
|
+
it("adds 'a' as child of root", () => {
|
|
19
|
+
const root = parse("a");
|
|
20
|
+
|
|
21
|
+
expect(root.children.has("a")).to.be.true;
|
|
22
|
+
});
|
|
23
|
+
it("initializes 'a' with the correct domain and parent", () => {
|
|
24
|
+
const root = parse("a");
|
|
25
|
+
const a = root.children.get("a");
|
|
26
|
+
|
|
27
|
+
expect(a.domain).to.equal("a");
|
|
28
|
+
expect(a.parent).to.equal(root);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe("when called with 'a,b'", () => {
|
|
32
|
+
it("adds 'a' and 'b' as child of root", () => {
|
|
33
|
+
const root = parse("a,b");
|
|
34
|
+
|
|
35
|
+
expect(root.children.has("a")).to.be.true;
|
|
36
|
+
expect(root.children.has("b")).to.be.true;
|
|
37
|
+
});
|
|
38
|
+
it("initializes 'b' with the correct domain and parent", () => {
|
|
39
|
+
const root = parse("a,b");
|
|
40
|
+
const b = root.children.get("b");
|
|
41
|
+
|
|
42
|
+
expect(b.domain).to.equal("b");
|
|
43
|
+
expect(b.parent).to.equal(root);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe("when called with 'a>b'", () => {
|
|
47
|
+
it("adds 'a' as child of root and 'b' as child of 'a'", () => {
|
|
48
|
+
const root = parse("a>b");
|
|
49
|
+
|
|
50
|
+
expect(root.children.has("a")).to.be.true;
|
|
51
|
+
expect(root.children.get("a").children.has("b")).to.be.true;
|
|
52
|
+
});
|
|
53
|
+
it("initializes 'b' with the correct domain and parent", () => {
|
|
54
|
+
const root = parse("a>b");
|
|
55
|
+
const a = root.children.get("a");
|
|
56
|
+
const b = a.children.get("b");
|
|
57
|
+
|
|
58
|
+
expect(b.domain).to.equal("b");
|
|
59
|
+
expect(b.parent).to.equal(a);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("when called with 'a>b,c'", () => {
|
|
63
|
+
it("adds 'b' and 'c' as child of 'a'", () => {
|
|
64
|
+
const root = parse("a>b,c");
|
|
65
|
+
const a = root.children.get("a");
|
|
66
|
+
|
|
67
|
+
expect(a.children.has("b")).to.be.true;
|
|
68
|
+
expect(a.children.has("c")).to.be.true;
|
|
69
|
+
});
|
|
70
|
+
it("initializes 'c' with the correct domain and parent", () => {
|
|
71
|
+
const root = parse("a>b,c");
|
|
72
|
+
const a = root.children.get("a");
|
|
73
|
+
const c = a.children.get("c");
|
|
74
|
+
|
|
75
|
+
expect(c.domain).to.equal("c");
|
|
76
|
+
expect(c.parent).to.equal(a);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("when called with 'a>b<c'", () => {
|
|
80
|
+
it("adds 'b' as child of 'a' and 'c' as child of root", () => {
|
|
81
|
+
const root = parse("a>b<c");
|
|
82
|
+
const a = root.children.get("a");
|
|
83
|
+
|
|
84
|
+
expect(a.children.has("b")).to.be.true;
|
|
85
|
+
expect(root.children.has("c")).to.be.true;
|
|
86
|
+
});
|
|
87
|
+
it("initializes 'c' with the correct domain and parent", () => {
|
|
88
|
+
const root = parse("a>b<c");
|
|
89
|
+
const c = root.children.get("c");
|
|
90
|
+
|
|
91
|
+
expect(c.domain).to.equal("c");
|
|
92
|
+
expect(c.parent).to.equal(root);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe("when called with 'a|b'", () => {
|
|
96
|
+
it("adds 'a' and 'b' as child of root", () => {
|
|
97
|
+
const root = parse("a|b");
|
|
98
|
+
|
|
99
|
+
expect(root.children.has("a")).to.be.true;
|
|
100
|
+
expect(root.children.has("b")).to.be.true;
|
|
101
|
+
});
|
|
102
|
+
it("initializes 'b' with the correct domain and parent", () => {
|
|
103
|
+
const root = parse("a|b");
|
|
104
|
+
const b = root.children.get("b");
|
|
105
|
+
|
|
106
|
+
expect(b.domain).to.equal("b");
|
|
107
|
+
expect(b.parent).to.equal(root);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe("when called with 'a>b|c'", () => {
|
|
111
|
+
it("adds 'b' as child of 'a' and 'c' as child of root", () => {
|
|
112
|
+
const root = parse("a>b|c");
|
|
113
|
+
const a = root.children.get("a");
|
|
114
|
+
|
|
115
|
+
expect(a.children.has("b")).to.be.true;
|
|
116
|
+
expect(root.children.has("c")).to.be.true;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe("when called with 'a>b<a>d'", () => {
|
|
120
|
+
it("adds 'b' and 'd' as child of 'a'", () => {
|
|
121
|
+
const root = parse("a>b<a>c");
|
|
122
|
+
const a = root.children.get("a");
|
|
123
|
+
|
|
124
|
+
expect(a.children.has("b")).to.be.true;
|
|
125
|
+
expect(a.children.has("c")).to.be.true;
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe("when called with 'a>b>c'", () => {
|
|
129
|
+
it("adds 'c' as child of 'b'", () => {
|
|
130
|
+
const root = parse("a>b>c");
|
|
131
|
+
const b = root.children.get("a").children.get("b");
|
|
132
|
+
|
|
133
|
+
expect(b.children.has("c")).to.be.true;
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe("when called with 'a>b>c>d|e'", () => {
|
|
137
|
+
it("adds 'e' as child node of root", () => {
|
|
138
|
+
const node = parse("a>b>c>d|e");
|
|
139
|
+
|
|
140
|
+
expect(node.children.has("e")).to.be.true;
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const chai = require("chai");
|
|
6
|
-
const parsePubSuffixList = require("../../lib/
|
|
6
|
+
const parsePubSuffixList = require("../../lib/trie/parsePubSuffixList");
|
|
7
7
|
|
|
8
8
|
const expect = chai.expect;
|
|
9
9
|
const pathToFixtures = path.resolve(__dirname, "..", "fixtures");
|
package/build/.DS_Store
DELETED
|
Binary file
|
package/lib/tries/lookUp.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var WILDCARD = "*";
|
|
4
|
-
var EXCEPTION = "!";
|
|
5
|
-
|
|
6
|
-
function lookUp(trie, hostname) {
|
|
7
|
-
var domains = hostname.split(".").reverse();
|
|
8
|
-
var tlds = [];
|
|
9
|
-
var currentTrie = trie;
|
|
10
|
-
|
|
11
|
-
for (var i = 0; i < domains.length; i++) {
|
|
12
|
-
var domain = domains[i];
|
|
13
|
-
var isWildcardRule = currentTrie.has(WILDCARD);
|
|
14
|
-
|
|
15
|
-
if (isWildcardRule) {
|
|
16
|
-
if (currentTrie.has(EXCEPTION + domain) === false) {
|
|
17
|
-
tlds.push(domain);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (currentTrie.has(domain) === false) {
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
tlds.push(domain);
|
|
28
|
-
var value = currentTrie.get(domain);
|
|
29
|
-
|
|
30
|
-
if (value === true) {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
currentTrie = value;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return tlds.length === 0 ? null : tlds.reverse().join(".");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = lookUp;
|
package/lib/tries/parseTrie.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var SEPARATORS = require("./separators");
|
|
4
|
-
|
|
5
|
-
function parseTrie(input) {
|
|
6
|
-
var map = new Map();
|
|
7
|
-
var parentMaps = [map];
|
|
8
|
-
var domain = "";
|
|
9
|
-
|
|
10
|
-
function setDomain(value) {
|
|
11
|
-
if (domain === "") {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
map.set(domain, value);
|
|
16
|
-
domain = "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
for (var i = 0; i < input.length; i++) {
|
|
20
|
-
var _char = input.charAt(i);
|
|
21
|
-
|
|
22
|
-
switch (_char) {
|
|
23
|
-
case SEPARATORS.SAME:
|
|
24
|
-
{
|
|
25
|
-
setDomain(true);
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
case SEPARATORS.DOWN:
|
|
30
|
-
{
|
|
31
|
-
var childMap = new Map();
|
|
32
|
-
setDomain(childMap);
|
|
33
|
-
parentMaps.push(map);
|
|
34
|
-
map = childMap;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
case SEPARATORS.RESET:
|
|
39
|
-
{
|
|
40
|
-
setDomain(true); // Remove all parent maps but the top most
|
|
41
|
-
|
|
42
|
-
parentMaps.length = 1;
|
|
43
|
-
map = parentMaps[0];
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
case SEPARATORS.UP:
|
|
48
|
-
{
|
|
49
|
-
setDomain(true);
|
|
50
|
-
map = parentMaps.pop();
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
domain += _char;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
setDomain(true);
|
|
59
|
-
return parentMaps[0];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = parseTrie;
|
package/lib/tries/separators.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const chai = require("chai");
|
|
4
|
-
const lookUp = require("../../lib/tries/lookUp");
|
|
5
|
-
|
|
6
|
-
const expect = chai.expect;
|
|
7
|
-
|
|
8
|
-
describe("lookUp()", () => {
|
|
9
|
-
it("returns null if the trie is empty", () => {
|
|
10
|
-
const trie = new Map();
|
|
11
|
-
const hostname = "a.b.c";
|
|
12
|
-
|
|
13
|
-
expect(lookUp(trie, hostname)).to.eql(null);
|
|
14
|
-
});
|
|
15
|
-
it("returns null if the trie contains no matching top-level domain", () => {
|
|
16
|
-
const trie = new Map();
|
|
17
|
-
const hostname = "a.b.c";
|
|
18
|
-
|
|
19
|
-
trie.set("cc", true);
|
|
20
|
-
|
|
21
|
-
expect(lookUp(trie, hostname)).to.eql(null);
|
|
22
|
-
});
|
|
23
|
-
it("returns the hostname if the hostname is a top-level domain", () => {
|
|
24
|
-
const trie = new Map();
|
|
25
|
-
const hostname = "a";
|
|
26
|
-
|
|
27
|
-
trie.set("a", true);
|
|
28
|
-
trie.set("b", true);
|
|
29
|
-
|
|
30
|
-
expect(lookUp(trie, hostname)).to.eql("a");
|
|
31
|
-
});
|
|
32
|
-
it("returns the top-level domain from the hostname (2 domains)", () => {
|
|
33
|
-
const trie = new Map();
|
|
34
|
-
const hostname = "b.a";
|
|
35
|
-
|
|
36
|
-
trie.set("a", true);
|
|
37
|
-
trie.set("b", true);
|
|
38
|
-
|
|
39
|
-
expect(lookUp(trie, hostname)).to.eql("a");
|
|
40
|
-
});
|
|
41
|
-
it("returns the top-level domain from the hostname (3 domains)", () => {
|
|
42
|
-
const trie = new Map();
|
|
43
|
-
const hostname = "c.b.a";
|
|
44
|
-
|
|
45
|
-
trie.set("a", true);
|
|
46
|
-
trie.set("b", true);
|
|
47
|
-
|
|
48
|
-
expect(lookUp(trie, hostname)).to.eql("a");
|
|
49
|
-
});
|
|
50
|
-
it("returns the top-level domain (2 tlds) from the hostname (3 domains)", () => {
|
|
51
|
-
const trie = new Map();
|
|
52
|
-
const trieA = new Map();
|
|
53
|
-
const hostname = "c.b.a";
|
|
54
|
-
|
|
55
|
-
trieA.set("b", true);
|
|
56
|
-
trie.set("a", trieA);
|
|
57
|
-
trie.set("b", new Map());
|
|
58
|
-
|
|
59
|
-
expect(lookUp(trie, hostname)).to.eql("b.a");
|
|
60
|
-
});
|
|
61
|
-
it("returns the top-level domain (3 tlds) from the hostname (4 domains)", () => {
|
|
62
|
-
const trie = new Map();
|
|
63
|
-
const trieA = new Map();
|
|
64
|
-
const trieAB = new Map();
|
|
65
|
-
const hostname = "d.c.b.a";
|
|
66
|
-
|
|
67
|
-
trieAB.set("c", true);
|
|
68
|
-
trieA.set("b", trieAB);
|
|
69
|
-
trieA.set("a", true);
|
|
70
|
-
trie.set("a", trieA);
|
|
71
|
-
trie.set("b", new Map());
|
|
72
|
-
|
|
73
|
-
expect(lookUp(trie, hostname)).to.eql("c.b.a");
|
|
74
|
-
});
|
|
75
|
-
it("interprets wildcards in the trie correctly (simple)", () => {
|
|
76
|
-
const trie = new Map();
|
|
77
|
-
const hostname = "a.b.c";
|
|
78
|
-
|
|
79
|
-
trie.set("*", true);
|
|
80
|
-
|
|
81
|
-
expect(lookUp(trie, hostname)).to.eql("c");
|
|
82
|
-
});
|
|
83
|
-
it("interprets wildcards in the trie correctly (nested)", () => {
|
|
84
|
-
const trie = new Map();
|
|
85
|
-
const trieA = new Map();
|
|
86
|
-
const hostname = "c.b.a";
|
|
87
|
-
|
|
88
|
-
trieA.set("*", true);
|
|
89
|
-
trie.set("a", trieA);
|
|
90
|
-
|
|
91
|
-
expect(lookUp(trie, hostname)).to.eql("b.a");
|
|
92
|
-
});
|
|
93
|
-
it("interprets exceptions of wildcards in the trie correctly (simple)", () => {
|
|
94
|
-
const trie = new Map();
|
|
95
|
-
const trieA = new Map();
|
|
96
|
-
const hostname = "c.b.a";
|
|
97
|
-
|
|
98
|
-
trieA.set("*", true);
|
|
99
|
-
trieA.set("!b", true);
|
|
100
|
-
trie.set("a", trieA);
|
|
101
|
-
|
|
102
|
-
expect(lookUp(trie, hostname)).to.eql("a");
|
|
103
|
-
});
|
|
104
|
-
it("still handles wildcards correctly if there are non-matching exceptions", () => {
|
|
105
|
-
const trie = new Map();
|
|
106
|
-
const trieA = new Map();
|
|
107
|
-
const hostname = "c.b.a";
|
|
108
|
-
|
|
109
|
-
trieA.set("*", true);
|
|
110
|
-
trieA.set("!a", true);
|
|
111
|
-
trieA.set("!c", true);
|
|
112
|
-
trie.set("a", trieA);
|
|
113
|
-
|
|
114
|
-
expect(lookUp(trie, hostname)).to.eql("b.a");
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const chai = require("chai");
|
|
4
|
-
const parseTrie = require("../../lib/tries/parseTrie");
|
|
5
|
-
|
|
6
|
-
const expect = chai.expect;
|
|
7
|
-
|
|
8
|
-
describe("parseTrie()", () => {
|
|
9
|
-
describe("basic cases", () => {
|
|
10
|
-
it("returns a map", () => {
|
|
11
|
-
expect(parseTrie("")).to.be.instanceOf(Map);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("returns an empty map when an empty string is given", () => {
|
|
15
|
-
const trie = parseTrie("");
|
|
16
|
-
|
|
17
|
-
expect(trie.size).to.equal(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("returns a map with the given domain as key and true as value", () => {
|
|
21
|
-
const trie = parseTrie("some-domain");
|
|
22
|
-
const someDomain = trie.get("some-domain");
|
|
23
|
-
|
|
24
|
-
expect(someDomain).to.equal(true);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe("with SAME separator", () => {
|
|
29
|
-
it("returns a map with the given domains as key and true as value", () => {
|
|
30
|
-
const trie = parseTrie("a,b,c");
|
|
31
|
-
const a = trie.get("a");
|
|
32
|
-
const b = trie.get("b");
|
|
33
|
-
const c = trie.get("c");
|
|
34
|
-
|
|
35
|
-
expect(a).to.equal(true);
|
|
36
|
-
expect(b).to.equal(true);
|
|
37
|
-
expect(c).to.equal(true);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("and with DOWN separator", () => {
|
|
42
|
-
it("returns a nested map", () => {
|
|
43
|
-
const trie = parseTrie("a>a");
|
|
44
|
-
const a = trie.get("a");
|
|
45
|
-
const aa = a.get("a");
|
|
46
|
-
|
|
47
|
-
expect(aa).to.equal(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("returns a deeply nested map", () => {
|
|
51
|
-
const trie = parseTrie("a>a>a");
|
|
52
|
-
const a = trie.get("a");
|
|
53
|
-
const aa = a.get("a");
|
|
54
|
-
const aaa = aa.get("a");
|
|
55
|
-
|
|
56
|
-
expect(aa).to.be.instanceOf(Map);
|
|
57
|
-
expect(aaa).to.equal(true);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("returns a nested map with the given domains as key and true as value", () => {
|
|
61
|
-
const trie = parseTrie("a>a,b,c");
|
|
62
|
-
const a = trie.get("a");
|
|
63
|
-
const aa = a.get("a");
|
|
64
|
-
const ab = a.get("b");
|
|
65
|
-
const ac = a.get("c");
|
|
66
|
-
|
|
67
|
-
expect(aa).to.equal(true);
|
|
68
|
-
expect(ab).to.equal(true);
|
|
69
|
-
expect(ac).to.equal(true);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("and with UP separator", () => {
|
|
74
|
-
it("returns a map with maps", () => {
|
|
75
|
-
const trie = parseTrie("a>a,b<b>a,b");
|
|
76
|
-
const a = trie.get("a");
|
|
77
|
-
const aa = a.get("a");
|
|
78
|
-
const ab = a.get("a");
|
|
79
|
-
const b = trie.get("b");
|
|
80
|
-
const ba = b.get("a");
|
|
81
|
-
const bb = b.get("b");
|
|
82
|
-
|
|
83
|
-
expect(aa).to.equal(true);
|
|
84
|
-
expect(ab).to.equal(true);
|
|
85
|
-
expect(ba).to.equal(true);
|
|
86
|
-
expect(bb).to.equal(true);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("goes up multiple levels", () => {
|
|
90
|
-
const trie = parseTrie("a>a>a>a<<<b");
|
|
91
|
-
const a = trie.get("a");
|
|
92
|
-
const aa = a.get("a");
|
|
93
|
-
const aaa = aa.get("a");
|
|
94
|
-
const aaaa = aaa.get("a");
|
|
95
|
-
const b = trie.get("b");
|
|
96
|
-
|
|
97
|
-
expect(aaaa).to.equal(true);
|
|
98
|
-
expect(b).to.equal(true);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("and with RESET separator", () => {
|
|
103
|
-
it("resets the domain level", () => {
|
|
104
|
-
const trie = parseTrie("a>a|b");
|
|
105
|
-
const a = trie.get("a");
|
|
106
|
-
const aa = a.get("a");
|
|
107
|
-
const b = trie.get("b");
|
|
108
|
-
|
|
109
|
-
expect(aa).to.equal(true);
|
|
110
|
-
expect(b).to.equal(true);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("works also on the top-level", () => {
|
|
114
|
-
const trie = parseTrie("a|b");
|
|
115
|
-
const a = trie.get("a");
|
|
116
|
-
const b = trie.get("b");
|
|
117
|
-
|
|
118
|
-
expect(a).to.equal(true);
|
|
119
|
-
expect(b).to.equal(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("returns the expected trie", () => {
|
|
123
|
-
const trie = parseTrie("a>a>a|b>a|c");
|
|
124
|
-
const a = trie.get("a");
|
|
125
|
-
const aa = a.get("a");
|
|
126
|
-
const aaa = aa.get("a");
|
|
127
|
-
const b = trie.get("b");
|
|
128
|
-
const ba = b.get("a");
|
|
129
|
-
const c = trie.get("c");
|
|
130
|
-
|
|
131
|
-
expect(aaa).to.equal(true);
|
|
132
|
-
expect(ba).to.equal(true);
|
|
133
|
-
expect(c).to.equal(true);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe("complex cases", () => {
|
|
138
|
-
it("parses 'a>a>a>a<<b,c|b>a>a<b>a>a,b' without errors", () => {
|
|
139
|
-
const trie = parseTrie("a>a>a>a<<b,c|b>a>a<b>a>a,b");
|
|
140
|
-
const a = trie.get("a");
|
|
141
|
-
const aa = a.get("a");
|
|
142
|
-
const aaa = aa.get("a");
|
|
143
|
-
const aaaa = aaa.get("a");
|
|
144
|
-
const ab = a.get("b");
|
|
145
|
-
const ac = a.get("c");
|
|
146
|
-
const b = trie.get("b");
|
|
147
|
-
const ba = b.get("a");
|
|
148
|
-
const baa = ba.get("a");
|
|
149
|
-
const bb = b.get("b");
|
|
150
|
-
const bba = bb.get("a");
|
|
151
|
-
const bbaa = bba.get("a");
|
|
152
|
-
const bbab = bba.get("b");
|
|
153
|
-
|
|
154
|
-
expect(aaaa).to.equal(true);
|
|
155
|
-
expect(ab).to.equal(true);
|
|
156
|
-
expect(ac).to.equal(true);
|
|
157
|
-
expect(baa).to.equal(true);
|
|
158
|
-
expect(bbaa).to.equal(true);
|
|
159
|
-
expect(bbab).to.equal(true);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|