-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
75 lines (61 loc) · 2.51 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const splitSelector = require("./index.js");
const splitSelectorBlocks = splitSelector.splitSelectorBlocks;
const joinSelector = splitSelector.joinSelector;
module.exports = {
splitSelector: {
splitsByComma: function(test) {
let selectors = splitSelector("div.someClass, a.another");
test.strictEqual(selectors[0], "div.someClass");
test.strictEqual(selectors[1], "a.another");
test.done();
},
recognisesOnlyOutterCommas: function(test) {
let selectors = splitSelector("a#item span , p[alt^='test , text']");
test.strictEqual(selectors[0], "a#item span");
test.strictEqual(selectors[1], "p[alt^='test , text']");
test.done();
}
},
splitSelectorBlocks: {
returnsSelectorsAndJoiners: function(test) {
let split = splitSelectorBlocks("a#item p[alt^='test , text']");
test.ok(split.selectors, "Selectors should be defined");
test.ok(split.joiners, "Joiners should be defined");
test.done();
},
returnsCorrectSelectorsAndJoiners: function(test) {
let split = splitSelectorBlocks("a#item p[alt^='test , text'] ~ span"),
selectors = split.selectors,
joiners = split.joiners;
test.strictEqual(selectors[0], "a#item");
test.strictEqual(selectors[1], "p[alt^='test , text']");
test.strictEqual(selectors[2], "span");
test.strictEqual(joiners[0], " ");
test.strictEqual(joiners[1], "~");
test.done();
},
understandsSpaceCombinations: function(test) {
let split = splitSelectorBlocks("div.entry-content > p > img"),
selectors = split.selectors,
joiners = split.joiners;
test.strictEqual(selectors[0], "div.entry-content");
test.strictEqual(selectors[1], "p");
test.strictEqual(selectors[2], "img");
test.strictEqual(selectors.length, 3);
test.strictEqual(joiners[0], ">");
test.strictEqual(joiners[1], ">");
test.strictEqual(joiners.length, 2);
test.done();
}
},
joinSelector: {
joinsCorrectly: function(test) {
let selector = joinSelector(
[ "#part1", ".part2", "[part3]" ],
[ " ", ">" ]
);
test.strictEqual(selector, "#part1 .part2 > [part3]");
test.done();
}
}
};