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

Powered by Google App Engine
This is Rietveld