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

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

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

Powered by Google App Engine
This is Rietveld