| Index: qunit/tests/filterValidation.js |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/qunit/tests/filterValidation.js |
| @@ -0,0 +1,80 @@ |
| +module( |
| + "filter validation", |
| + { |
| + setup: function() |
| + { |
| + var filterValidation = require("filterValidation"); |
| + this.parseFilter = filterValidation.parseFilter; |
| + this.parseFilters = filterValidation.parseFilters; |
| + |
| + var filterClasses = require("filterClasses"); |
| + this.BlockingFilter = filterClasses.BlockingFilter; |
| + this.ElemHideFilter = filterClasses.ElemHideFilter; |
| + 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
|
| + } |
| + } |
| +); |
| + |
| +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.
|
| + 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.
|
| + throws(this.parseFilter.bind(null, "[foobar]"), "filter list header"); |
| + throws(this.parseFilter.bind(null, "##[foo"), "invalid selector"); |
| +}); |
| + |
| +test("allowing valid filters", function() { |
| + var text, filter; |
| + |
| + 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.
|
| + filter = this.parseFilter(text); |
| + ok(filter instanceof this.BlockingFilter && filter.text == text, "blocking filter"); |
|
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.
|
| + |
| + text = '##div:first-child a[src="http://example.com"] > .foo + #bar' |
| + filter = this.parseFilter(text); |
| + ok(filter instanceof this.ElemHideFilter && filter.text == text, "elemhide filter"); |
| + |
| + text = "! foo bar" |
| + filter = this.parseFilter(text); |
| + ok(filter instanceof this.CommentFilter && filter.text == text, "comment filter"); |
| + |
| + 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.
|
| +}); |
| + |
| +test("parsing multiple filters", function() |
| +{ |
| + var filters; |
| + |
| + filters = this.parseFilters("||example.com\n \n###foobar\r\n! foo bar\n"); |
| + ok( |
| + filters.length == 3 && |
| + |
| + filters[0] instanceof this.BlockingFilter && |
| + filters[0].text == "||example.com" && |
| + |
| + filters[1] instanceof this.ElemHideFilter && |
| + filters[1].text == "###foobar" && |
| + |
| + filters[2] instanceof this.CommentFilter && |
| + filters[2].text == "! foo bar", |
| + |
| + "parse filters and comments, stripping empty lines" |
| + ); |
| + |
| + filters = this.parseFilters("[foobar]\n \n||example.com\r\n! foo bar\n", true); |
| + ok( |
| + filters.length == 2 && |
| + |
| + filters[0] instanceof this.BlockingFilter && |
| + filters[0].text == "||example.com" && |
| + |
| + filters[1] instanceof this.CommentFilter && |
| + filters[1].text == "! foo bar", |
| + |
| + "parse filters and comments, stripping empty lines and filter list headers" |
| + ); |
| + |
| + throws( |
| + this.parseFilters.bind(null, "!comment\r\n||example.com\n\n##/"), |
| + /^([^:]+ )?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
|
| + "throw error with corresponding line number" |
| + ); |
| +}); |