Index: test/filterClasses.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/test/filterClasses.js |
@@ -0,0 +1,52 @@ |
+"use strict"; |
+ |
+let filterClasses = require("../lib/filterClassesNew"); |
+let Filter = filterClasses.Filter; |
+let InvalidFilter = filterClasses.InvalidFilter; |
+let CommentFilter = filterClasses.CommentFilter; |
+let RegExpFilter = filterClasses.RegExpFilter; |
+let ElemHideFilter = filterClasses.ElemHideFilter; |
+let ElemHideException = filterClasses.ElemHideException; |
+ |
+exports.testFromText = function(test) |
+{ |
+ let tests = [ |
+ ["!asdf", CommentFilter, "comment"], |
+ ["asdf", RegExpFilter, "blocking"], |
+ ["##asdf", ElemHideFilter, "elemhide"], |
+ ["#@#asdf", ElemHideException, "elemhideexception"], |
+ ["foobar##asdf", ElemHideFilter, "elemhide"], |
+ ["foobar#@#asdf", ElemHideException, "elemhideexception"], |
+ ["foobar##a", ElemHideFilter, "elemhide"], |
+ ["foobar#@#a", ElemHideException, "elemhideexception"], |
+ |
+ ["foobar#asdf", RegExpFilter, "blocking"], |
+ ["foobar|foobas##asdf", RegExpFilter, "blocking"], |
+ ["foobar##asdf{asdf}", RegExpFilter, "blocking"], |
+ ["foobar##", RegExpFilter, "blocking"], |
+ ["foobar#@#", RegExpFilter, "blocking"], |
+ ]; |
+ for (let [text, type, typeName] of tests) |
+ { |
+ let filter = Filter.fromText(text); |
+ test.ok(filter, "Got filter for " + text); |
+ test.ok(filter instanceof type, "Correct filter type for " + text); |
+ test.equal(filter.type, typeName, "Type name for " + text + " is " + typeName); |
+ } |
+ test.done(); |
+} |
+ |
+exports.testNormalize = function(test) |
+{ |
+ let tests = [ |
+ [" foo bar ", "foobar"], |
+ ["foobar", "foobar"], |
+ [" ! comment something ", "! comment something"], |
+ [" ! \n comment something ", "! comment something"], |
+ [" foo , bar ## foo > bar ", "foo,bar##foo > bar"], |
+ [" foo , bar #@# foo > bar ", "foo,bar#@#foo > bar"], |
+ ]; |
+ for (let [text, expected] of tests) |
+ test.equal(Filter.normalize(text), expected); |
+ test.done(); |
+} |