OLD | NEW |
(Empty) | |
| 1 "use strict"; |
| 2 |
| 3 let filterClasses = require("../lib/filterClassesNew"); |
| 4 let Filter = filterClasses.Filter; |
| 5 let InvalidFilter = filterClasses.InvalidFilter; |
| 6 let CommentFilter = filterClasses.CommentFilter; |
| 7 let RegExpFilter = filterClasses.RegExpFilter; |
| 8 let ElemHideFilter = filterClasses.ElemHideFilter; |
| 9 let ElemHideException = filterClasses.ElemHideException; |
| 10 |
| 11 exports.testFromText = function(test) |
| 12 { |
| 13 let tests = [ |
| 14 ["!asdf", CommentFilter, "comment"], |
| 15 ["asdf", RegExpFilter, "blocking"], |
| 16 ["##asdf", ElemHideFilter, "elemhide"], |
| 17 ["#@#asdf", ElemHideException, "elemhideexception"], |
| 18 ["foobar##asdf", ElemHideFilter, "elemhide"], |
| 19 ["foobar#@#asdf", ElemHideException, "elemhideexception"], |
| 20 ["foobar##a", ElemHideFilter, "elemhide"], |
| 21 ["foobar#@#a", ElemHideException, "elemhideexception"], |
| 22 |
| 23 ["foobar#asdf", RegExpFilter, "blocking"], |
| 24 ["foobar|foobas##asdf", RegExpFilter, "blocking"], |
| 25 ["foobar##asdf{asdf}", RegExpFilter, "blocking"], |
| 26 ["foobar##", RegExpFilter, "blocking"], |
| 27 ["foobar#@#", RegExpFilter, "blocking"], |
| 28 ]; |
| 29 for (let [text, type, typeName] of tests) |
| 30 { |
| 31 let filter = Filter.fromText(text); |
| 32 test.ok(filter instanceof Filter, "Got filter for " + text); |
| 33 test.equal(filter.text, text, "Correct filter text for " + text); |
| 34 test.ok(filter instanceof type, "Correct filter type for " + text); |
| 35 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam
e); |
| 36 } |
| 37 test.done(); |
| 38 } |
| 39 |
| 40 exports.testNormalize = function(test) |
| 41 { |
| 42 let tests = [ |
| 43 [" foo bar ", "foobar"], |
| 44 ["foobar", "foobar"], |
| 45 [" ! comment something ", "! comment something"], |
| 46 [" ! \n comment something ", "! comment something"], |
| 47 [" foo , bar ## foo > bar ", "foo,bar##foo > bar"], |
| 48 [" foo , bar #@# foo > bar ", "foo,bar#@#foo > bar"], |
| 49 ]; |
| 50 for (let [text, expected] of tests) |
| 51 test.equal(Filter.normalize(text), expected); |
| 52 test.done(); |
| 53 } |
| 54 |
| 55 exports.testActiveFilter = function(test) |
| 56 { |
| 57 let filter1 = Filter.fromText("asdf"); |
| 58 let filter1copy = Filter.fromText("asdf"); |
| 59 let filter2 = Filter.fromText("##foobar"); |
| 60 |
| 61 test.ok(!filter1.disabled && !filter1copy.disabled && !filter2.disabled, "Filt
ers are initially enabled"); |
| 62 filter1.disabled = true; |
| 63 test.ok(filter1.disabled, "Disabling filter works"); |
| 64 test.ok(filter1copy.disabled, "Filter copies are also disabled"); |
| 65 test.ok(!filter2.disabled, "Disabling one filter doesn't disable others"); |
| 66 |
| 67 test.ok(filter1.hitCount === 0 && filter1copy.hitCount === 0 && filter2.hitCou
nt === 0, "Filters have no hit initially"); |
| 68 filter1.hitCount = 5; |
| 69 test.equal(filter1.hitCount, 5, "Changing hit count works"); |
| 70 test.equal(filter1copy.hitCount, 5, "Hit count of filter copies is also change
d"); |
| 71 test.equal(filter2.hitCount, 0, "Hit count of other filters isn't affected"); |
| 72 |
| 73 test.ok(filter1.lastHit === 0 && filter1copy.lastHit === 0 && filter2.lastHit
=== 0, "Filters have no last hit time initially"); |
| 74 filter1.lastHit = 10; |
| 75 test.equal(filter1.lastHit, 10, "Changing last hit time works"); |
| 76 test.equal(filter1copy.lastHit, 10, "Last hit time of filter copies is also ch
anged"); |
| 77 test.equal(filter2.lastHit, 0, "Last hit time of other filters isn't affected"
); |
| 78 |
| 79 test.done(); |
| 80 } |
OLD | NEW |