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 try |
| 33 { |
| 34 test.ok(filter instanceof Filter, "Got filter for " + text); |
| 35 test.equal(filter.text, text, "Correct filter text for " + text); |
| 36 test.ok(filter instanceof type, "Correct filter type for " + text); |
| 37 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeN
ame); |
| 38 } |
| 39 finally |
| 40 { |
| 41 filter.delete(); |
| 42 } |
| 43 } |
| 44 test.done(); |
| 45 } |
| 46 |
| 47 exports.testNormalize = function(test) |
| 48 { |
| 49 let tests = [ |
| 50 [" foo bar ", "foobar"], |
| 51 ["foobar", "foobar"], |
| 52 [" ! comment something ", "! comment something"], |
| 53 [" ! \n comment something ", "! comment something"], |
| 54 [" foo , bar ## foo > bar ", "foo,bar##foo > bar"], |
| 55 [" foo , bar #@# foo > bar ", "foo,bar#@#foo > bar"], |
| 56 ]; |
| 57 for (let [text, expected] of tests) |
| 58 test.equal(Filter.normalize(text), expected); |
| 59 test.done(); |
| 60 } |
| 61 |
| 62 exports.testActiveFilter = function(test) |
| 63 { |
| 64 let filter1 = Filter.fromText("asdf"); |
| 65 let filter1copy = Filter.fromText("asdf"); |
| 66 let filter2 = Filter.fromText("##foobar"); |
| 67 |
| 68 try |
| 69 { |
| 70 test.ok(!filter1.disabled && !filter1copy.disabled && !filter2.disabled, "Fi
lters are initially enabled"); |
| 71 filter1.disabled = true; |
| 72 test.ok(filter1.disabled, "Disabling filter works"); |
| 73 test.ok(filter1copy.disabled, "Filter copies are also disabled"); |
| 74 test.ok(!filter2.disabled, "Disabling one filter doesn't disable others"); |
| 75 |
| 76 test.ok(filter1.hitCount === 0 && filter1copy.hitCount === 0 && filter2.hitC
ount === 0, "Filters have no hit initially"); |
| 77 filter1.hitCount = 5; |
| 78 test.equal(filter1.hitCount, 5, "Changing hit count works"); |
| 79 test.equal(filter1copy.hitCount, 5, "Hit count of filter copies is also chan
ged"); |
| 80 test.equal(filter2.hitCount, 0, "Hit count of other filters isn't affected")
; |
| 81 |
| 82 test.ok(filter1.lastHit === 0 && filter1copy.lastHit === 0 && filter2.lastHi
t === 0, "Filters have no last hit time initially"); |
| 83 filter1.lastHit = 10; |
| 84 test.equal(filter1.lastHit, 10, "Changing last hit time works"); |
| 85 test.equal(filter1copy.lastHit, 10, "Last hit time of filter copies is also
changed"); |
| 86 test.equal(filter2.lastHit, 0, "Last hit time of other filters isn't affecte
d"); |
| 87 } |
| 88 finally |
| 89 { |
| 90 filter1.delete(); |
| 91 filter1copy.delete(); |
| 92 filter2.delete(); |
| 93 } |
| 94 |
| 95 test.done(); |
| 96 } |
OLD | NEW |