Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: qunit/tests/filterValidation.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Update adblockplusui dependency Created March 16, 2017, 8:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « qunit/tests/cssEscaping.js ('k') | qunit/tests/prefs.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 "use strict"; 1 "use strict";
2 2
3 (function()
3 { 4 {
4 const {parseFilter, parseFilters} = require("filterValidation"); 5 const {parseFilter, parseFilters} = require("filterValidation");
5 const {BlockingFilter, 6 const {BlockingFilter,
6 ElemHideFilter, 7 ElemHideFilter,
7 CommentFilter} = require("filterClasses"); 8 CommentFilter} = require("filterClasses");
8 9
9 module("Filter validation"); 10 module("Filter validation");
10 11
11 test("Detecting invalid filters", () => 12 test("Detecting invalid filters", () =>
12 { 13 {
13 equal(parseFilter("||example.com^$unknown").error.type, "invalid-filter", "u nknown option"); 14 equal(parseFilter("||example.com^$unknown").error.type, "invalid-filter",
14 equal(parseFilter("[foobar]").error.type, "unexpected-filter-list-header", " filter list header"); 15 "unknown option");
15 equal(parseFilter("##[foo").error.type, "invalid-css-selector", "invalid sel ector"); 16 equal(parseFilter("[foobar]").error.type, "unexpected-filter-list-header",
16 ok(/\b4\b/.test(parseFilters("!comment\r\n||example.com^\n\n##/").errors[0]) , "error contains corresponding line number"); 17 "filter list header");
18 equal(parseFilter("##[foo").error.type, "invalid-css-selector",
19 "invalid selector");
20 ok(
21 /\b4\b/.test(parseFilters("!comment\r\n||example.com^\n\n##/").errors[0]),
22 "error contains corresponding line number"
23 );
17 }); 24 });
18 25
19 test("Allowing valid filters", () => 26 test("Allowing valid filters", () =>
20 { 27 {
21 let text, filter; 28 let text;
29 let filter;
22 30
23 text = "||example.com^"; 31 text = "||example.com^";
24 filter = parseFilter(text).filter; 32 ({filter} = parseFilter(text));
25 ok(filter instanceof BlockingFilter, "blocking filter parsed"); 33 ok(filter instanceof BlockingFilter, "blocking filter parsed");
26 equal(filter.text, text, "blocking filter text matches"); 34 equal(filter.text, text, "blocking filter text matches");
27 35
28 text = '##div:first-child a[src="http://example.com"] > .foo + #bar'; 36 text = '##div:first-child a[src="http://example.com"] > .foo + #bar';
29 filter = parseFilter(text).filter; 37 ({filter} = parseFilter(text));
30 ok(filter instanceof ElemHideFilter, "elemhide filter parsed"); 38 ok(filter instanceof ElemHideFilter, "elemhide filter parsed");
31 equal(filter.text, text, "elemhide filter text matches"); 39 equal(filter.text, text, "elemhide filter text matches");
32 40
33 text = "! foo bar"; 41 text = "! foo bar";
34 filter = parseFilter(text).filter; 42 ({filter} = parseFilter(text));
35 ok(filter instanceof CommentFilter, "comment filter parsed"); 43 ok(filter instanceof CommentFilter, "comment filter parsed");
36 equal(filter.text, text, "comment filter text matches"); 44 equal(filter.text, text, "comment filter text matches");
37 45
38 equal(parseFilter("").filter, null, "empty filter parsed as 'null'"); 46 equal(parseFilter("").filter, null, "empty filter parsed as 'null'");
39 }); 47 });
40 48
41 test("Normalizing filters", () => 49 test("Normalizing filters", () =>
42 { 50 {
43 let ws = " \t\r\n"; 51 let ws = " \t\r\n";
44 52 let filterText = ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws;
45 equal(parseFilter(ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws ).filter.text, "@@||example.com^", "unnecessary spaces"); 53 equal(parseFilter(filterText).filter.text, "@@||example.com^",
54 "unnecessary spaces");
46 equal(parseFilter(ws).filter, null, "only spaces"); 55 equal(parseFilter(ws).filter, null, "only spaces");
47 }); 56 });
48 57
49 test("Parsing multiple filters", () => 58 test("Parsing multiple filters", () =>
50 { 59 {
51 let result = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n"); 60 let result = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n");
52 61
53 equal(result.errors.length, 0, "no error occurred"); 62 equal(result.errors.length, 0, "no error occurred");
54 equal(result.filters.length, 3, "all filters parsed"); 63 equal(result.filters.length, 3, "all filters parsed");
55 64
56 ok(result.filters[0] instanceof BlockingFilter, "1st filter is blocking"); 65 ok(result.filters[0] instanceof BlockingFilter, "1st filter is blocking");
57 equal(result.filters[0].text, "||example.com^", "1st filter text matches"); 66 equal(result.filters[0].text, "||example.com^", "1st filter text matches");
58 67
59 ok(result.filters[1] instanceof ElemHideFilter, "2nd filter is elemhide"); 68 ok(result.filters[1] instanceof ElemHideFilter, "2nd filter is elemhide");
60 equal(result.filters[1].text, "###foobar", "2nd filter text matches"); 69 equal(result.filters[1].text, "###foobar", "2nd filter text matches");
61 70
62 ok(result.filters[2] instanceof CommentFilter, "3rd filter is comment"); 71 ok(result.filters[2] instanceof CommentFilter, "3rd filter is comment");
63 equal(result.filters[2].text, "! foo bar", "3rd filter text matches"); 72 equal(result.filters[2].text, "! foo bar", "3rd filter text matches");
64 }); 73 });
65 } 74 }());
OLDNEW
« no previous file with comments | « qunit/tests/cssEscaping.js ('k') | qunit/tests/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld