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

Side by Side Diff: test/filterClasses.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Now passing all filter matching tests (without filter options) Created Jan. 18, 2016, 6:12 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
« no previous file with comments | « test.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 "use strict";
2
3 let {
4 Filter, InvalidFilter, CommentFilter, RegExpFilter, WhiteListFilter,
5 ElemHideFilter, ElemHideException
6 } = require("../lib/filterClassesNew");
7
8 Filter.fromText("/asdf??+/");
9
10 exports.testFromText = function(test)
11 {
12 let tests = [
13 ["!asdf", CommentFilter, "comment"],
14 ["asdf", RegExpFilter, "blocking"],
15 ["asdf$image,~collapse", RegExpFilter, "blocking"],
16 ["/asdf/", RegExpFilter, "blocking"],
17 ["/asdf??+/", InvalidFilter, "invalid"],
18 ["@@asdf", WhiteListFilter, "whitelist"],
19 ["@@asdf$image,~collapse", WhiteListFilter, "whitelist"],
20 ["@@/asdf/", WhiteListFilter, "whitelist"],
21 ["@@/asdf??+/", InvalidFilter, "invalid"],
22 ["##asdf", ElemHideFilter, "elemhide"],
23 ["#@#asdf", ElemHideException, "elemhideexception"],
24 ["foobar##asdf", ElemHideFilter, "elemhide"],
25 ["foobar#@#asdf", ElemHideException, "elemhideexception"],
26 ["foobar##a", ElemHideFilter, "elemhide"],
27 ["foobar#@#a", ElemHideException, "elemhideexception"],
28
29 ["foobar#asdf", RegExpFilter, "blocking"],
30 ["foobar|foobas##asdf", RegExpFilter, "blocking"],
31 ["foobar##asdf{asdf}", RegExpFilter, "blocking"],
32 ["foobar##", RegExpFilter, "blocking"],
33 ["foobar#@#", RegExpFilter, "blocking"],
34 ];
35 for (let [text, type, typeName, location] of tests)
36 {
37 let filter = Filter.fromText(text);
38 try
39 {
40 test.ok(filter instanceof Filter, "Got filter for " + text);
41 test.equal(filter.text, text, "Correct filter text for " + text);
42 test.ok(filter instanceof type, "Correct filter type for " + text);
43 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeN ame);
44 if (type == InvalidFilter)
45 test.ok(filter.reason, "Invalid filter " + text + " has a reason set");
46 }
47 finally
48 {
49 filter.delete();
50 }
51 }
52 test.done();
53 };
54
55 exports.testNormalize = function(test)
56 {
57 let tests = [
58 [" foo bar ", "foobar"],
59 ["foobar", "foobar"],
60 [" ! comment something ", "! comment something"],
61 [" ! \n comment something ", "! comment something"],
62 [" foo , bar ## foo > bar ", "foo,bar##foo > bar"],
63 [" foo , bar #@# foo > bar ", "foo,bar#@#foo > bar"],
64 ];
65 for (let [text, expected] of tests)
66 test.equal(Filter.normalize(text), expected);
67 test.done();
68 };
69
70 exports.testActiveFilter = function(test)
71 {
72 let filter1 = Filter.fromText("asdf");
73 let filter1copy = Filter.fromText("asdf");
74 let filter2 = Filter.fromText("##foobar");
75
76 try
77 {
78 test.ok(!filter1.disabled && !filter1copy.disabled && !filter2.disabled, "Fi lters are initially enabled");
79 filter1.disabled = true;
80 test.ok(filter1.disabled, "Disabling filter works");
81 test.ok(filter1copy.disabled, "Filter copies are also disabled");
82 test.ok(!filter2.disabled, "Disabling one filter doesn't disable others");
83
84 test.ok(filter1.hitCount === 0 && filter1copy.hitCount === 0 && filter2.hitC ount === 0, "Filters have no hit initially");
85 filter1.hitCount = 5;
86 test.equal(filter1.hitCount, 5, "Changing hit count works");
87 test.equal(filter1copy.hitCount, 5, "Hit count of filter copies is also chan ged");
88 test.equal(filter2.hitCount, 0, "Hit count of other filters isn't affected") ;
89
90 test.ok(filter1.lastHit === 0 && filter1copy.lastHit === 0 && filter2.lastHi t === 0, "Filters have no last hit time initially");
91 filter1.lastHit = 10;
92 test.equal(filter1.lastHit, 10, "Changing last hit time works");
93 test.equal(filter1copy.lastHit, 10, "Last hit time of filter copies is also changed");
94 test.equal(filter2.lastHit, 0, "Last hit time of other filters isn't affecte d");
95 }
96 finally
97 {
98 filter1.delete();
99 filter1copy.delete();
100 filter2.delete();
101 }
102
103 test.done();
104 };
105
106 exports.testMatching = function(test)
107 {
108 function testMatch(text, location, contentType, docDomain, thirdParty, sitekey , expected)
109 {
110 let filter = Filter.fromText(text);
111 test.equal(filter.matches(location), expected, "Result of filter " + text + " matching " + location);
112 filter.delete();
113
114 filter = Filter.fromText("@@" + text)
115 test.equal(filter.matches(location), expected, "Result of filter @@" + text + " matching " + location);
116 filter.delete();
117 }
118
119 // Basic filters
120 testMatch("abc", "http://abc/adf", "IMAGE", null, false, null, true);
121 testMatch("abc", "http://ABC/adf", "IMAGE", null, false, null, true);
122 testMatch("abc", "http://abd/adf", "IMAGE", null, false, null, false);
123 testMatch("|abc", "http://abc/adf", "IMAGE", null, false, null, false);
124 testMatch("|http://abc", "http://abc/adf", "IMAGE", null, false, null, true);
125 testMatch("abc|", "http://abc/adf", "IMAGE", null, false, null, false);
126 testMatch("abc/adf|", "http://abc/adf", "IMAGE", null, false, null, true);
127 testMatch("||example.com/foo", "http://example.com/foo/bar", "IMAGE", null, fa lse, null, true);
128 testMatch("||com/foo", "http://example.com/foo/bar", "IMAGE", null, false, nul l, true);
129 testMatch("||mple.com/foo", "http://example.com/foo/bar", "IMAGE", null, false , null, false);
130 testMatch("||/example.com/foo", "http://example.com/foo/bar", "IMAGE", null, f alse, null, false);
131 testMatch("||example.com/foo/bar|", "http://example.com/foo/bar", "IMAGE", nul l, false, null, true);
132 testMatch("||example.com/foo", "http://foo.com/http://example.com/foo/bar", "I MAGE", null, false, null, false);
133 testMatch("||example.com/foo|", "http://example.com/foo/bar", "IMAGE", null, f alse, null, false);
134
135 // Separator placeholders
136 testMatch("abc^d", "http://abc/def", "IMAGE", null, false, null, true);
137 testMatch("abc^e", "http://abc/def", "IMAGE", null, false, null, false);
138 testMatch("def^", "http://abc/def", "IMAGE", null, false, null, true);
139 testMatch("http://abc/d^f", "http://abc/def", "IMAGE", null, false, null, fals e);
140 testMatch("http://abc/def^", "http://abc/def", "IMAGE", null, false, null, tru e);
141 testMatch("^foo=bar^", "http://abc/?foo=bar", "IMAGE", null, false, null, true );
142 testMatch("^foo=bar^", "http://abc/?a=b&foo=bar", "IMAGE", null, false, null, true);
143 testMatch("^foo=bar^", "http://abc/?foo=bar&a=b", "IMAGE", null, false, null, true);
144 testMatch("^foo=bar^", "http://abc/?notfoo=bar", "IMAGE", null, false, null, f alse);
145 testMatch("^foo=bar^", "http://abc/?foo=barnot", "IMAGE", null, false, null, f alse);
146 testMatch("^foo=bar^", "http://abc/?foo=bar%2Enot", "IMAGE", null, false, null , false);
147 testMatch("||example.com^", "http://example.com/foo/bar", "IMAGE", null, false , null, true);
148 testMatch("||example.com^", "http://example.company.com/foo/bar", "IMAGE", nul l, false, null, false);
149 testMatch("||example.com^", "http://example.com:1234/foo/bar", "IMAGE", null, false, null, true);
150 testMatch("||example.com^", "http://example.com.com/foo/bar", "IMAGE", null, f alse, null, false);
151 testMatch("||example.com^", "http://example.com-company.com/foo/bar", "IMAGE", null, false, null, false);
152 testMatch("||example.com^foo", "http://example.com/foo/bar", "IMAGE", null, fa lse, null, true);
153 testMatch("||пример.ру^", "http://пример.ру/foo/bar", "IMAGE", null, false, nu ll, true);
154 testMatch("||пример.ру^", "http://пример.руководитель.ру/foo/bar", "IMAGE", nu ll, false, null, false);
155 testMatch("||пример.ру^", "http://пример.ру:1234/foo/bar", "IMAGE", null, fals e, null, true);
156 testMatch("||пример.ру^", "http://пример.ру.ру/foo/bar", "IMAGE", null, false, null, false);
157 testMatch("||пример.ру^", "http://пример.ру-ководитель.ру/foo/bar", "IMAGE", n ull, false, null, false);
158 testMatch("||пример.ру^foo", "http://пример.ру/foo/bar", "IMAGE", null, false, null, true);
159
160 // Wildcard matching
161 testMatch("abc*d", "http://abc/adf", "IMAGE", null, false, null, true);
162 testMatch("abc*d", "http://abcd/af", "IMAGE", null, false, null, true);
163 testMatch("abc*d", "http://abc/d/af", "IMAGE", null, false, null, true);
164 testMatch("abc*d", "http://dabc/af", "IMAGE", null, false, null, false);
165 testMatch("*abc", "http://abc/adf", "IMAGE", null, false, null, true);
166 testMatch("abc*", "http://abc/adf", "IMAGE", null, false, null, true);
167 testMatch("|*abc", "http://abc/adf", "IMAGE", null, false, null, true);
168 testMatch("abc*|", "http://abc/adf", "IMAGE", null, false, null, true);
169 testMatch("abc***d", "http://abc/adf", "IMAGE", null, false, null, true);
170
171 // Regular expressions
172 testMatch("/abc/", "http://abc/adf", "IMAGE", null, false, null, true);
173 testMatch("/abc/", "http://abcd/adf", "IMAGE", null, false, null, true);
174 testMatch("*/abc/", "http://abc/adf", "IMAGE", null, false, null, true);
175 testMatch("*/abc/", "http://abcd/adf", "IMAGE", null, false, null, false);
176 testMatch("/a\\wc/", "http://abc/adf", "IMAGE", null, false, null, true);
177 testMatch("/a\\wc/", "http://a1c/adf", "IMAGE", null, false, null, true);
178 testMatch("/a\\wc/", "http://a_c/adf", "IMAGE", null, false, null, true);
179 testMatch("/a\\wc/", "http://a%c/adf", "IMAGE", null, false, null, false);
180
181 test.done();
182 };
OLDNEW
« no previous file with comments | « test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld