OLD | NEW |
1 "use strict"; | 1 "use strict"; |
2 | 2 |
| 3 (function() |
3 { | 4 { |
4 const {Filter, ElemHideFilter} = require("filterClasses"); | 5 const {Filter, ElemHideFilter} = require("filterClasses"); |
5 const {escapeCSS, quoteCSS} = require("filterComposer"); | 6 const {escapeCSS, quoteCSS} = require("filterComposer"); |
6 | 7 |
7 module("CSS escaping"); | 8 module("CSS escaping"); |
8 | 9 |
9 test("CSS escaping", () => | 10 test("CSS escaping", () => |
10 { | 11 { |
11 function testSelector(opts) | 12 function testSelector(opts) |
12 { | 13 { |
(...skipping 23 matching lines...) Expand all Loading... |
36 for (let attr in opts.attributes) | 37 for (let attr in opts.attributes) |
37 element.setAttribute(attr, opts.attributes[attr]); | 38 element.setAttribute(attr, opts.attributes[attr]); |
38 | 39 |
39 doc.documentElement.appendChild(element); | 40 doc.documentElement.appendChild(element); |
40 } | 41 } |
41 | 42 |
42 let foundElement = doc.querySelector(opts.selector); | 43 let foundElement = doc.querySelector(opts.selector); |
43 let filter = Filter.fromText("##" + opts.selector); | 44 let filter = Filter.fromText("##" + opts.selector); |
44 | 45 |
45 if (!(filter instanceof ElemHideFilter)) | 46 if (!(filter instanceof ElemHideFilter)) |
46 { | |
47 ok(false, opts.selector + " (not allowed in elemhide filters)"); | 47 ok(false, opts.selector + " (not allowed in elemhide filters)"); |
48 } | 48 else if (mustMatch) |
| 49 equal(foundElement, element, opts.selector); |
49 else | 50 else |
50 { | 51 ok(true, opts.selector); |
51 if (mustMatch) | |
52 equal(foundElement, element, opts.selector); | |
53 else | |
54 ok(true, opts.selector); | |
55 } | |
56 } | 52 } |
57 | 53 |
58 function testEscape(s) | 54 function testEscape(s) |
59 { | 55 { |
60 testSelector({ | 56 testSelector({ |
61 selector: escapeCSS(s), | 57 selector: escapeCSS(s), |
62 tagName: s | 58 tagName: s |
63 }); | 59 }); |
64 | 60 |
65 testSelector({ | 61 testSelector({ |
(...skipping 26 matching lines...) Expand all Loading... |
92 | 88 |
93 // Some characters are only escaped when in the first positon, | 89 // Some characters are only escaped when in the first positon, |
94 // so we still have to make sure that everything is correctly escaped | 90 // so we still have to make sure that everything is correctly escaped |
95 // in subsequent positions. | 91 // in subsequent positions. |
96 testEscape("x" + chr); | 92 testEscape("x" + chr); |
97 | 93 |
98 // Leading dashes must be escaped, when followed by certain characters. | 94 // Leading dashes must be escaped, when followed by certain characters. |
99 testEscape("-" + chr); | 95 testEscape("-" + chr); |
100 } | 96 } |
101 | 97 |
102 // Test some non-ASCII characters. However, those shouldn't require escaping
. | 98 // Test some non-ASCII characters. However, those shouldn't |
| 99 // require escaping. |
103 testEscape("\uD83D\uDE3B\u2665\u00E4"); | 100 testEscape("\uD83D\uDE3B\u2665\u00E4"); |
104 }); | 101 }); |
105 } | 102 }()); |
OLD | NEW |