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