Left: | ||
Right: |
OLD | NEW |
---|---|
1 (function() | 1 (function() |
2 { | 2 { |
3 var filterValidation = require("filterValidation"); | 3 var filterValidation = require("filterValidation"); |
4 var parseFilter = filterValidation.parseFilter; | 4 var parseFilter = filterValidation.parseFilter; |
5 var parseFilters = filterValidation.parseFilters; | 5 var parseFilters = filterValidation.parseFilters; |
6 | 6 |
7 var filterClasses = require("filterClasses"); | 7 var filterClasses = require("filterClasses"); |
8 var BlockingFilter = filterClasses.BlockingFilter; | 8 var BlockingFilter = filterClasses.BlockingFilter; |
9 var ElemHideFilter = filterClasses.ElemHideFilter; | 9 var ElemHideFilter = filterClasses.ElemHideFilter; |
10 var CommentFilter = filterClasses.CommentFilter; | 10 var CommentFilter = filterClasses.CommentFilter; |
11 | 11 |
12 module("Filter validation"); | 12 module("Filter validation"); |
13 | 13 |
14 test("Detecting invalid filters", function() | 14 test("Detecting invalid filters", function() |
15 { | 15 { |
16 ok(parseFilter("||example.com^$unknown").error, "unknown option"); | 16 equal(parseFilter("||example.com^$unknown").error.type, "invalid-filter", "u nknown option"); |
17 ok(parseFilter("[foobar]").error, "filter list header"); | 17 equal(parseFilter("[foobar]").error.type, "unexpected-filter-list-header", " filter list header"); |
18 ok(parseFilter("##[foo").error, "invalid selector"); | 18 equal(parseFilter("##[foo").error.type, "invalid-css-selector", "invalid sel ector"); |
19 ok(/\b4\b/.test(parseFilters("!comment\r\n||example.com^\n\n##/").error), "e rror contains corresponding line number"); | 19 ok(/\b4\b/.test(parseFilters("!comment\r\n||example.com^\n\n##/").errors[0]) , "error contains corresponding line number"); |
Wladimir Palant
2015/06/08 18:15:47
Maybe test for line number field here instead of p
Sebastian Noack
2015/06/08 18:36:46
I considered that. But then decided to keep it as
Wladimir Palant
2015/06/08 19:14:16
Well, I'm not going to insist - I merely dislike p
| |
20 }); | 20 }); |
21 | 21 |
22 test("Allowing valid filters", function() | 22 test("Allowing valid filters", function() |
23 { | 23 { |
24 var text, filter; | 24 var text, filter; |
25 | 25 |
26 text = "||example.com^"; | 26 text = "||example.com^"; |
27 filter = parseFilter(text).filter; | 27 filter = parseFilter(text).filter; |
28 ok(filter instanceof BlockingFilter, "blocking filter parsed"); | 28 ok(filter instanceof BlockingFilter, "blocking filter parsed"); |
29 equal(filter.text, text, "blocking filter text matches"); | 29 equal(filter.text, text, "blocking filter text matches"); |
(...skipping 14 matching lines...) Expand all Loading... | |
44 test("Normalizing filters", function() | 44 test("Normalizing filters", function() |
45 { | 45 { |
46 var ws = " \t\r\n"; | 46 var ws = " \t\r\n"; |
47 | 47 |
48 equal(parseFilter(ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws ).filter.text, "@@||example.com^", "unnecessary spaces"); | 48 equal(parseFilter(ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws ).filter.text, "@@||example.com^", "unnecessary spaces"); |
49 equal(parseFilter(ws).filter, null, "only spaces"); | 49 equal(parseFilter(ws).filter, null, "only spaces"); |
50 }); | 50 }); |
51 | 51 |
52 test("Parsing multiple filters", function() | 52 test("Parsing multiple filters", function() |
53 { | 53 { |
54 var filters = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n").fi lters; | 54 var result = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n"); |
55 | 55 |
56 equal(filters.length, 3, "all filters parsed"); | 56 equal(result.errors.length, 0, "no error occurred"); |
57 equal(result.filters.length, 3, "all filters parsed"); | |
57 | 58 |
58 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking"); | 59 ok(result.filters[0] instanceof BlockingFilter, "1st filter is blocking"); |
59 equal(filters[0].text, "||example.com^", "1st filter text matches"); | 60 equal(result.filters[0].text, "||example.com^", "1st filter text matches"); |
60 | 61 |
61 ok(filters[1] instanceof ElemHideFilter, "2nd filter is elemhide"); | 62 ok(result.filters[1] instanceof ElemHideFilter, "2nd filter is elemhide"); |
62 equal(filters[1].text, "###foobar", "2nd filter text matches"); | 63 equal(result.filters[1].text, "###foobar", "2nd filter text matches"); |
63 | 64 |
64 ok(filters[2] instanceof CommentFilter, "3rd filter is comment"); | 65 ok(result.filters[2] instanceof CommentFilter, "3rd filter is comment"); |
65 equal(filters[2].text, "! foo bar", "3rd filter text matches"); | 66 equal(result.filters[2].text, "! foo bar", "3rd filter text matches"); |
66 }); | |
67 | |
68 test("Parsing multiple filters, stripping filter list headers", function() | |
69 { | |
70 var filters = parseFilters("[foobar]\n \n||example.com^\r\n! foo bar\n", tru e).filters; | |
71 | |
72 equal(filters.length, 2, "all filters parsed"); | |
73 | |
74 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking"); | |
75 equal(filters[0].text, "||example.com^", "1st filter text matches"); | |
76 | |
77 ok(filters[1] instanceof CommentFilter, "2nd filter is comment"); | |
78 equal(filters[1].text, "! foo bar", "2nd filter text matches"); | |
79 }); | 67 }); |
80 })(); | 68 })(); |
OLD | NEW |