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: Back to manual approach for API Created Jan. 18, 2016, 12:41 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", "http://foobar/asdfxyz"],
17 ["/asdf??+/", InvalidFilter, "invalid"],
18 ["@@asdf", WhiteListFilter, "whitelist"],
19 ["@@asdf$image,~collapse", WhiteListFilter, "whitelist"],
20 ["@@/asdf/", WhiteListFilter, "whitelist", "http://foobar/asdfxyz"],
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 if (location)
47 {
48 test.ok(filter.matches(location), "Filter " + text + " matches location " + location);
49
50 location = "http://foobardummy/";
51 test.ok(!filter.matches(location), "Filter " + text + " doesn't match lo cation " + location);
52 }
53 }
54 finally
55 {
56 filter.delete();
57 }
58 }
59 test.done();
60 }
61
62 exports.testNormalize = function(test)
63 {
64 let tests = [
65 [" foo bar ", "foobar"],
66 ["foobar", "foobar"],
67 [" ! comment something ", "! comment something"],
68 [" ! \n comment something ", "! comment something"],
69 [" foo , bar ## foo > bar ", "foo,bar##foo > bar"],
70 [" foo , bar #@# foo > bar ", "foo,bar#@#foo > bar"],
71 ];
72 for (let [text, expected] of tests)
73 test.equal(Filter.normalize(text), expected);
74 test.done();
75 }
76
77 exports.testActiveFilter = function(test)
78 {
79 let filter1 = Filter.fromText("asdf");
80 let filter1copy = Filter.fromText("asdf");
81 let filter2 = Filter.fromText("##foobar");
82
83 try
84 {
85 test.ok(!filter1.disabled && !filter1copy.disabled && !filter2.disabled, "Fi lters are initially enabled");
86 filter1.disabled = true;
87 test.ok(filter1.disabled, "Disabling filter works");
88 test.ok(filter1copy.disabled, "Filter copies are also disabled");
89 test.ok(!filter2.disabled, "Disabling one filter doesn't disable others");
90
91 test.ok(filter1.hitCount === 0 && filter1copy.hitCount === 0 && filter2.hitC ount === 0, "Filters have no hit initially");
92 filter1.hitCount = 5;
93 test.equal(filter1.hitCount, 5, "Changing hit count works");
94 test.equal(filter1copy.hitCount, 5, "Hit count of filter copies is also chan ged");
95 test.equal(filter2.hitCount, 0, "Hit count of other filters isn't affected") ;
96
97 test.ok(filter1.lastHit === 0 && filter1copy.lastHit === 0 && filter2.lastHi t === 0, "Filters have no last hit time initially");
98 filter1.lastHit = 10;
99 test.equal(filter1.lastHit, 10, "Changing last hit time works");
100 test.equal(filter1copy.lastHit, 10, "Last hit time of filter copies is also changed");
101 test.equal(filter2.lastHit, 0, "Last hit time of other filters isn't affecte d");
102 }
103 finally
104 {
105 filter1.delete();
106 filter1copy.delete();
107 filter2.delete();
108 }
109
110 test.done();
111 }
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