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: Rebased. Created March 7, 2017, 10:44 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 { 3 {
4 const {parseFilter, parseFilters} = require("filterValidation"); 4 const {parseFilter, parseFilters} = require("filterValidation");
5 const {BlockingFilter, 5 const {BlockingFilter,
6 ElemHideFilter, 6 ElemHideFilter,
7 CommentFilter} = require("filterClasses"); 7 CommentFilter} = require("filterClasses");
8 8
9 module("Filter validation"); 9 module("Filter validation");
10 10
11 test("Detecting invalid filters", () => 11 test("Detecting invalid filters", () =>
12 { 12 {
13 equal(parseFilter("||example.com^$unknown").error.type, "invalid-filter", "u nknown option"); 13 equal(parseFilter("||example.com^$unknown").error.type, "invalid-filter",
14 equal(parseFilter("[foobar]").error.type, "unexpected-filter-list-header", " filter list header"); 14 "unknown option");
15 equal(parseFilter("##[foo").error.type, "invalid-css-selector", "invalid sel ector"); 15 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"); 16 "filter list header");
17 equal(parseFilter("##[foo").error.type, "invalid-css-selector",
18 "invalid selector");
19 ok(
20 /\b4\b/.test(parseFilters("!comment\r\n||example.com^\n\n##/").errors[0]),
21 "error contains corresponding line number"
22 );
17 }); 23 });
18 24
19 test("Allowing valid filters", () => 25 test("Allowing valid filters", () =>
20 { 26 {
21 let text, filter; 27 let text;
28 let filter;
22 29
23 text = "||example.com^"; 30 text = "||example.com^";
24 filter = parseFilter(text).filter; 31 ({filter} = parseFilter(text));
25 ok(filter instanceof BlockingFilter, "blocking filter parsed"); 32 ok(filter instanceof BlockingFilter, "blocking filter parsed");
26 equal(filter.text, text, "blocking filter text matches"); 33 equal(filter.text, text, "blocking filter text matches");
27 34
28 text = '##div:first-child a[src="http://example.com"] > .foo + #bar'; 35 text = '##div:first-child a[src="http://example.com"] > .foo + #bar';
29 filter = parseFilter(text).filter; 36 ({filter} = parseFilter(text));
30 ok(filter instanceof ElemHideFilter, "elemhide filter parsed"); 37 ok(filter instanceof ElemHideFilter, "elemhide filter parsed");
31 equal(filter.text, text, "elemhide filter text matches"); 38 equal(filter.text, text, "elemhide filter text matches");
32 39
33 text = "! foo bar"; 40 text = "! foo bar";
34 filter = parseFilter(text).filter; 41 ({filter} = parseFilter(text));
35 ok(filter instanceof CommentFilter, "comment filter parsed"); 42 ok(filter instanceof CommentFilter, "comment filter parsed");
36 equal(filter.text, text, "comment filter text matches"); 43 equal(filter.text, text, "comment filter text matches");
37 44
38 equal(parseFilter("").filter, null, "empty filter parsed as 'null'"); 45 equal(parseFilter("").filter, null, "empty filter parsed as 'null'");
39 }); 46 });
40 47
41 test("Normalizing filters", () => 48 test("Normalizing filters", () =>
42 { 49 {
43 let ws = " \t\r\n"; 50 let ws = " \t\r\n";
44 51 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"); 52 equal(parseFilter(filterText).filter.text, "@@||example.com^",
53 "unnecessary spaces");
46 equal(parseFilter(ws).filter, null, "only spaces"); 54 equal(parseFilter(ws).filter, null, "only spaces");
47 }); 55 });
48 56
49 test("Parsing multiple filters", () => 57 test("Parsing multiple filters", () =>
50 { 58 {
51 let result = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n"); 59 let result = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n");
52 60
53 equal(result.errors.length, 0, "no error occurred"); 61 equal(result.errors.length, 0, "no error occurred");
54 equal(result.filters.length, 3, "all filters parsed"); 62 equal(result.filters.length, 3, "all filters parsed");
55 63
56 ok(result.filters[0] instanceof BlockingFilter, "1st filter is blocking"); 64 ok(result.filters[0] instanceof BlockingFilter, "1st filter is blocking");
57 equal(result.filters[0].text, "||example.com^", "1st filter text matches"); 65 equal(result.filters[0].text, "||example.com^", "1st filter text matches");
58 66
59 ok(result.filters[1] instanceof ElemHideFilter, "2nd filter is elemhide"); 67 ok(result.filters[1] instanceof ElemHideFilter, "2nd filter is elemhide");
60 equal(result.filters[1].text, "###foobar", "2nd filter text matches"); 68 equal(result.filters[1].text, "###foobar", "2nd filter text matches");
61 69
62 ok(result.filters[2] instanceof CommentFilter, "3rd filter is comment"); 70 ok(result.filters[2] instanceof CommentFilter, "3rd filter is comment");
63 equal(result.filters[2].text, "! foo bar", "3rd filter text matches"); 71 equal(result.filters[2].text, "! foo bar", "3rd filter text matches");
64 }); 72 });
65 } 73 }
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