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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/filterClasses.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/filterClasses.js
@@ -0,0 +1,111 @@
+"use strict";
+
+let {
+ Filter, InvalidFilter, CommentFilter, RegExpFilter, WhiteListFilter,
+ ElemHideFilter, ElemHideException
+} = require("../lib/filterClassesNew");
+
+Filter.fromText("/asdf??+/");
+
+exports.testFromText = function(test)
+{
+ let tests = [
+ ["!asdf", CommentFilter, "comment"],
+ ["asdf", RegExpFilter, "blocking"],
+ ["asdf$image,~collapse", RegExpFilter, "blocking"],
+ ["/asdf/", RegExpFilter, "blocking", "http://foobar/asdfxyz"],
+ ["/asdf??+/", InvalidFilter, "invalid"],
+ ["@@asdf", WhiteListFilter, "whitelist"],
+ ["@@asdf$image,~collapse", WhiteListFilter, "whitelist"],
+ ["@@/asdf/", WhiteListFilter, "whitelist", "http://foobar/asdfxyz"],
+ ["@@/asdf??+/", InvalidFilter, "invalid"],
+ ["##asdf", ElemHideFilter, "elemhide"],
+ ["#@#asdf", ElemHideException, "elemhideexception"],
+ ["foobar##asdf", ElemHideFilter, "elemhide"],
+ ["foobar#@#asdf", ElemHideException, "elemhideexception"],
+ ["foobar##a", ElemHideFilter, "elemhide"],
+ ["foobar#@#a", ElemHideException, "elemhideexception"],
+
+ ["foobar#asdf", RegExpFilter, "blocking"],
+ ["foobar|foobas##asdf", RegExpFilter, "blocking"],
+ ["foobar##asdf{asdf}", RegExpFilter, "blocking"],
+ ["foobar##", RegExpFilter, "blocking"],
+ ["foobar#@#", RegExpFilter, "blocking"],
+ ];
+ for (let [text, type, typeName, location] of tests)
+ {
+ let filter = Filter.fromText(text);
+ try
+ {
+ test.ok(filter instanceof Filter, "Got filter for " + text);
+ test.equal(filter.text, text, "Correct filter text for " + text);
+ test.ok(filter instanceof type, "Correct filter type for " + text);
+ test.equal(filter.type, typeName, "Type name for " + text + " is " + typeName);
+ if (type == InvalidFilter)
+ test.ok(filter.reason, "Invalid filter " + text + " has a reason set");
+ if (location)
+ {
+ test.ok(filter.matches(location), "Filter " + text + " matches location " + location);
+
+ location = "http://foobardummy/";
+ test.ok(!filter.matches(location), "Filter " + text + " doesn't match location " + location);
+ }
+ }
+ finally
+ {
+ filter.delete();
+ }
+ }
+ test.done();
+}
+
+exports.testNormalize = function(test)
+{
+ let tests = [
+ [" foo bar ", "foobar"],
+ ["foobar", "foobar"],
+ [" ! comment something ", "! comment something"],
+ [" ! \n comment something ", "! comment something"],
+ [" foo , bar ## foo > bar ", "foo,bar##foo > bar"],
+ [" foo , bar #@# foo > bar ", "foo,bar#@#foo > bar"],
+ ];
+ for (let [text, expected] of tests)
+ test.equal(Filter.normalize(text), expected);
+ test.done();
+}
+
+exports.testActiveFilter = function(test)
+{
+ let filter1 = Filter.fromText("asdf");
+ let filter1copy = Filter.fromText("asdf");
+ let filter2 = Filter.fromText("##foobar");
+
+ try
+ {
+ test.ok(!filter1.disabled && !filter1copy.disabled && !filter2.disabled, "Filters are initially enabled");
+ filter1.disabled = true;
+ test.ok(filter1.disabled, "Disabling filter works");
+ test.ok(filter1copy.disabled, "Filter copies are also disabled");
+ test.ok(!filter2.disabled, "Disabling one filter doesn't disable others");
+
+ test.ok(filter1.hitCount === 0 && filter1copy.hitCount === 0 && filter2.hitCount === 0, "Filters have no hit initially");
+ filter1.hitCount = 5;
+ test.equal(filter1.hitCount, 5, "Changing hit count works");
+ test.equal(filter1copy.hitCount, 5, "Hit count of filter copies is also changed");
+ test.equal(filter2.hitCount, 0, "Hit count of other filters isn't affected");
+
+ test.ok(filter1.lastHit === 0 && filter1copy.lastHit === 0 && filter2.lastHit === 0, "Filters have no last hit time initially");
+ filter1.lastHit = 10;
+ test.equal(filter1.lastHit, 10, "Changing last hit time works");
+ test.equal(filter1copy.lastHit, 10, "Last hit time of filter copies is also changed");
+ test.equal(filter2.lastHit, 0, "Last hit time of other filters isn't affected");
+ }
+ finally
+ {
+ filter1.delete();
+ filter1copy.delete();
+ filter2.delete();
+ }
+
+ test.done();
+}
« no previous file with comments | « test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld