Index: test/elemHide.js |
=================================================================== |
--- a/test/elemHide.js |
+++ b/test/elemHide.js |
@@ -16,31 +16,32 @@ |
*/ |
"use strict"; |
const {createSandbox} = require("./_common"); |
let ElemHide = null; |
let createStyleSheet = null; |
+let rulesFromStyleSheet = null; |
let ElemHideExceptions = null; |
let Filter = null; |
let filtersByDomain = null; |
let selectorGroupSize = null; |
exports.setUp = function(callback) |
{ |
let sandboxedRequire = createSandbox({ |
extraExports: { |
elemHide: ["filtersByDomain", "selectorGroupSize"] |
} |
}); |
( |
- {ElemHide, createStyleSheet, filtersByDomain, selectorGroupSize} = |
- sandboxedRequire("../lib/elemHide"), |
+ {ElemHide, createStyleSheet, rulesFromStyleSheet, |
+ filtersByDomain, selectorGroupSize} = sandboxedRequire("../lib/elemHide"), |
{ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), |
{Filter} = sandboxedRequire("../lib/filterClasses") |
); |
callback(); |
}; |
function normalizeSelectors(selectors) |
@@ -300,8 +301,23 @@ |
test.equal((createStyleSheet(selectors).match(/\n/g) || []).length, |
Math.ceil(50000 / selectorGroupSize), |
"Style sheet should be split up into rules with at most " + |
selectorGroupSize + " selectors each"); |
test.done(); |
}; |
+ |
+exports.testRulesFromStyleSheet = function(test) |
+{ |
+ // Note: The rulesFromStyleSheet function assumes that each rule will be |
+ // terminated with a newline character, including the last rule. If this is |
+ // not the case, the function goes into an infinite loop. It should only be |
+ // used with the return value of the createStyleSheet function. |
+ |
+ test.deepEqual([...rulesFromStyleSheet("")], []); |
+ test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]); |
+ test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")], |
+ ["#foo {}", "#bar {}"]); |
+ |
+ test.done(); |
+}; |