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

Delta Between Two Patch Sets: qunit/tests/filterValidation.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
Left Patch Set: Addressed comments Created Nov. 20, 2014, 3:35 p.m.
Right Patch Set: Improved test messages Created Nov. 21, 2014, 8:07 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « qunit/index.html ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 (function() 1 (function()
2 { 2 {
3 var filterValidation = require("filterValidation"); 3 var filterValidation = require("filterValidation");
4 var parseFilter = filterValidation.parseFilter; 4 var parseFilter = filterValidation.parseFilter;
5 var parseFilters = filterValidation.parseFilters; 5 var parseFilters = filterValidation.parseFilters;
6 6
7 var filterClasses = require("filterClasses"); 7 var filterClasses = require("filterClasses");
8 var BlockingFilter = filterClasses.BlockingFilter; 8 var BlockingFilter = filterClasses.BlockingFilter;
9 var ElemHideFilter = filterClasses.ElemHideFilter; 9 var ElemHideFilter = filterClasses.ElemHideFilter;
10 var CommentFilter = filterClasses.CommentFilter; 10 var CommentFilter = filterClasses.CommentFilter;
11 11
12 module("Filter validation"); 12 module("Filter validation");
13 13
14 test("Detecting invalid filters", function() 14 test("Detecting invalid filters", function()
15 { 15 {
16 throws(parseFilter.bind(null, "||example.com^$unknown"), "unknown option"); 16 throws(parseFilter.bind(null, "||example.com^$unknown"), "unknown option");
17 throws(parseFilter.bind(null, "[foobar]"), "filter list header"); 17 throws(parseFilter.bind(null, "[foobar]"), "filter list header");
18 throws(parseFilter.bind(null, "##[foo"), "invalid selector"); 18 throws(parseFilter.bind(null, "##[foo"), "invalid selector");
19 19
20 throws(parseFilters.bind(null, "!comment\r\n||example.com^\n\n##/"), /\b4\b/ , "error contains corresponding line number"); 20 throws(parseFilters.bind(null, "!comment\r\n||example.com^\n\n##/"), /\b4\b/ , "error contains corresponding line number");
21 }); 21 });
22 22
23 test("Allowing valid filters", function() 23 test("Allowing valid filters", function()
24 { 24 {
25 var text, filter; 25 var text, filter;
26 26
27 text = "||example.com^"; 27 text = "||example.com^";
28 filter = parseFilter(text); 28 filter = parseFilter(text);
29 ok(filter instanceof BlockingFilter, "blocking filter"); 29 ok(filter instanceof BlockingFilter, "blocking filter parsed");
30 equal(filter.text, text, "blocking filter text"); 30 equal(filter.text, text, "blocking filter text matches");
31 31
32 text = '##div:first-child a[src="http://example.com"] > .foo + #bar' 32 text = '##div:first-child a[src="http://example.com"] > .foo + #bar'
33 filter = parseFilter(text); 33 filter = parseFilter(text);
34 ok(filter instanceof ElemHideFilter, "elemhide filter"); 34 ok(filter instanceof ElemHideFilter, "elemhide filter parsed");
35 equal(filter.text, text, "elemhide filter text"); 35 equal(filter.text, text, "elemhide filter text matches");
36 36
37 text = "! foo bar" 37 text = "! foo bar"
38 filter = parseFilter(text); 38 filter = parseFilter(text);
39 ok(filter instanceof CommentFilter, "comment filter"); 39 ok(filter instanceof CommentFilter, "comment filter parsed");
40 equal(filter.text, text, "comment filter text"); 40 equal(filter.text, text, "comment filter text matches");
41 41
42 equal(parseFilter(""), null, "empty filter"); 42 equal(parseFilter(""), null, "empty filter parsed as 'null'");
43 }); 43 });
44 44
45 test("Normalizing filters", function() 45 test("Normalizing filters", function()
46 { 46 {
47 var ws = " \t\r\n"; 47 var ws = " \t\r\n";
48 48
49 equal(parseFilter(ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws ).text, "@@||example.com^", "unnecessary spaces"); 49 equal(parseFilter(ws + "@@" + ws + "||" + ws + "example.com" + ws + "^" + ws ).text, "@@||example.com^", "unnecessary spaces");
50 equal(parseFilter(ws), null, "only spaces"); 50 equal(parseFilter(ws), null, "only spaces");
51 }); 51 });
52 52
53 test("Parsing multiple filters", function() 53 test("Parsing multiple filters", function()
54 { 54 {
55 var filters = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n"); 55 var filters = parseFilters("||example.com^\n \n###foobar\r\n! foo bar\n");
56 56
57 equal(filters.length, 3, "there are 3 filters"); 57 equal(filters.length, 3, "all filters parsed");
Wladimir Palant 2014/11/20 16:58:20 Nit: You are duplicating the expected result in th
Sebastian Noack 2014/11/21 08:08:08 Done, and improved a few other messages as well.
58 58
59 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking"); 59 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking");
60 equal(filters[0].text, "||example.com^", "1st filter text matches"); 60 equal(filters[0].text, "||example.com^", "1st filter text matches");
61 61
62 ok(filters[1] instanceof ElemHideFilter, "2nd filter is elemhide"); 62 ok(filters[1] instanceof ElemHideFilter, "2nd filter is elemhide");
63 equal(filters[1].text, "###foobar", "2nd filter text matches"); 63 equal(filters[1].text, "###foobar", "2nd filter text matches");
64 64
65 ok(filters[2] instanceof CommentFilter, "3rd filter is comment"); 65 ok(filters[2] instanceof CommentFilter, "3rd filter is comment");
66 equal(filters[2].text, "! foo bar", "3rd filter text matches"); 66 equal(filters[2].text, "! foo bar", "3rd filter text matches");
67 }); 67 });
68 68
69 test("Parsing multiple filters, stripping filter list headers", function() 69 test("Parsing multiple filters, stripping filter list headers", function()
70 { 70 {
71 var filters = parseFilters("[foobar]\n \n||example.com^\r\n! foo bar\n", tru e); 71 var filters = parseFilters("[foobar]\n \n||example.com^\r\n! foo bar\n", tru e);
72 72
73 equal(filters.length, 2, "there are 2 filters"); 73 equal(filters.length, 2, "all filters parsed");
74 74
75 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking"); 75 ok(filters[0] instanceof BlockingFilter, "1st filter is blocking");
76 equal(filters[0].text, "||example.com^", "1st filter text matches"); 76 equal(filters[0].text, "||example.com^", "1st filter text matches");
77 77
78 ok(filters[1] instanceof CommentFilter, "2nd filter is comment"); 78 ok(filters[1] instanceof CommentFilter, "2nd filter is comment");
79 equal(filters[1].text, "! foo bar", "2nd filter text matches"); 79 equal(filters[1].text, "! foo bar", "2nd filter text matches");
80 }); 80 });
81 })(); 81 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld