Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 module( | |
2 "filter validation", | |
3 { | |
4 setup: function() | |
5 { | |
6 var filterValidation = require("filterValidation"); | |
7 this.parseFilter = filterValidation.parseFilter; | |
8 this.parseFilters = filterValidation.parseFilters; | |
9 | |
10 var filterClasses = require("filterClasses"); | |
11 this.BlockingFilter = filterClasses.BlockingFilter; | |
12 this.ElemHideFilter = filterClasses.ElemHideFilter; | |
13 this.CommentFilter = filterClasses.CommentFilter; | |
Wladimir Palant
2014/11/20 14:10:06
It makes relatively little sense to require module
Sebastian Noack
2014/11/20 15:36:29
Done, but I used an IFEE, to don't pollute the glo
Wladimir Palant
2014/11/20 16:58:20
Right, they don't run in their own context... Actu
| |
14 } | |
15 } | |
16 ); | |
17 | |
18 test("detecting invalid filters", function() { | |
Wladimir Palant
2014/11/20 14:10:06
Nit: Here and below, test names are usually capita
Sebastian Noack
2014/11/20 15:36:29
Done.
| |
19 throws(this.parseFilter.bind(null, "||example.com$unknown"), "unkown option"); | |
Wladimir Palant
2014/11/20 14:10:06
Typo: "unkown"
Sebastian Noack
2014/11/20 15:36:29
Done.
| |
20 throws(this.parseFilter.bind(null, "[foobar]"), "filter list header"); | |
21 throws(this.parseFilter.bind(null, "##[foo"), "invalid selector"); | |
22 }); | |
23 | |
24 test("allowing valid filters", function() { | |
25 var text, filter; | |
26 | |
27 text = "||example.com"; | |
Wladimir Palant
2014/11/20 14:10:06
Nit: Better "||example.com^" - a separator placeho
Sebastian Noack
2014/11/20 15:36:29
Done.
| |
28 filter = this.parseFilter(text); | |
29 ok(filter instanceof this.BlockingFilter && filter.text == text, "blocking fil ter"); | |
Wladimir Palant
2014/11/20 14:10:06
Here and everywhere else, please use a separate ch
Sebastian Noack
2014/11/20 15:36:29
Done.
| |
30 | |
31 text = '##div:first-child a[src="http://example.com"] > .foo + #bar' | |
32 filter = this.parseFilter(text); | |
33 ok(filter instanceof this.ElemHideFilter && filter.text == text, "elemhide fil ter"); | |
34 | |
35 text = "! foo bar" | |
36 filter = this.parseFilter(text); | |
37 ok(filter instanceof this.CommentFilter && filter.text == text, "comment filte r"); | |
38 | |
39 equal(this.parseFilter(""), null, "empty filter"); | |
Wladimir Palant
2014/11/20 14:10:06
Might be a good idea to test that filter normaliza
Sebastian Noack
2014/11/20 15:36:29
Done.
| |
40 }); | |
41 | |
42 test("parsing multiple filters", function() | |
43 { | |
44 var filters; | |
45 | |
46 filters = this.parseFilters("||example.com\n \n###foobar\r\n! foo bar\n"); | |
47 ok( | |
48 filters.length == 3 && | |
49 | |
50 filters[0] instanceof this.BlockingFilter && | |
51 filters[0].text == "||example.com" && | |
52 | |
53 filters[1] instanceof this.ElemHideFilter && | |
54 filters[1].text == "###foobar" && | |
55 | |
56 filters[2] instanceof this.CommentFilter && | |
57 filters[2].text == "! foo bar", | |
58 | |
59 "parse filters and comments, stripping empty lines" | |
60 ); | |
61 | |
62 filters = this.parseFilters("[foobar]\n \n||example.com\r\n! foo bar\n", true) ; | |
63 ok( | |
64 filters.length == 2 && | |
65 | |
66 filters[0] instanceof this.BlockingFilter && | |
67 filters[0].text == "||example.com" && | |
68 | |
69 filters[1] instanceof this.CommentFilter && | |
70 filters[1].text == "! foo bar", | |
71 | |
72 "parse filters and comments, stripping empty lines and filter list headers" | |
73 ); | |
74 | |
75 throws( | |
76 this.parseFilters.bind(null, "!comment\r\n||example.com\n\n##/"), | |
77 /^([^:]+ )?4( [^:]+)?:/, | |
Wladimir Palant
2014/11/20 14:10:06
No point overcomplicating this, how about /\b4\b/?
Sebastian Noack
2014/11/20 15:36:29
My concern was that there can be digits occurring
| |
78 "throw error with corresponding line number" | |
79 ); | |
80 }); | |
OLD | NEW |