Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Unified Diff: node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/test/nth-check.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/test/nth-check.js
diff --git a/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/test/nth-check.js b/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/test/nth-check.js
new file mode 100644
index 0000000000000000000000000000000000000000..2a3b8158f2989a23d38fa3a793c06fb84a84744f
--- /dev/null
+++ b/node_modules/vulcanize/node_modules/whacko/node_modules/CSSselect/test/nth-check.js
@@ -0,0 +1,117 @@
+var nthCheck = require("../lib/nth-check.js"),
+ assert = require("assert");
+
+var invalid = ["-", "asdf", "2n+-0", "2+0", "- 1n", "-1 n"];
+function parseInvalid(){
+ invalid.forEach(function(formula){
+ assert.throws(function(){
+ nthCheck.parse(formula);
+ },
+ SyntaxError,
+ formula
+ );
+ });
+}
+
+var valid = {
+ "1": [ 0, 1 ],
+ "2": [ 0, 2 ],
+ "3": [ 0, 3 ],
+ "5": [ 0, 5 ],
+ " 1 ": [ 0, 1 ],
+ " 5 ": [ 0, 5 ],
+ "+2n + 1": [ 2, 1 ],
+ "-1": [ 0, -1 ],
+ "-1n + 3": [ -1, 3 ],
+ "-1n+3": [ -1, 3 ],
+ "-n+2": [ -1, 2 ],
+ "-n+3": [ -1, 3 ],
+ "0n+3": [ 1, 3 ],
+ "1n": [ 1, 0 ],
+ "1n+0": [ 1, 0 ],
+ "2n": [ 2, 0 ],
+ "2n + 1": [ 2, 1 ],
+ "2n+1": [ 2, 1 ],
+ "3n": [ 3, 0 ],
+ "3n+0": [ 3, 0 ],
+ "3n+1": [ 3, 1 ],
+ "3n+2": [ 3, 2 ],
+ "3n+3": [ 3, 3 ],
+ "3n-1": [ 3, -1 ],
+ "3n-2": [ 3, -2 ],
+ "3n-3": [ 3, -3 ],
+ even: [ 2, 0 ],
+ n: [ 1, 0 ],
+ "n+2": [ 1, 2 ],
+ odd: [ 2, 1 ],
+
+ //surprisingly, neither sizzle, qwery or nwmatcher cover these cases
+ "-4n+13": [-4, 13],
+ "-2n + 12": [-2, 12]
+};
+
+function parseValid(){
+ Object.keys(valid).forEach(function(formula){
+ assert.deepEqual(nthCheck.parse(formula), valid[formula], formula);
+ });
+}
+
+function testValid(){
+ Object.keys(valid).forEach(function(formula){
+ testFormula(valid[formula], formula);
+ });
+}
+
+var LIMIT = 1e3;
+
+var valArray = (function(){
+ var elems = [];
+ for(var i = 0; i <= LIMIT; i++) elems.push(i);
+ return elems;
+}());
+
+function testFormula(formula, name){
+ var filtered = valArray.filter(nthCheck.compile(formula)),
+ iterated = stupidNth(formula);
+
+ try {
+ assert.deepEqual(filtered, iterated, name);
+ } catch(e){
+ e.expected = JSON.stringify(iterated) + " " + name;
+ e.actual = JSON.stringify(filtered) + " " + name;
+ throw e;
+ }
+}
+
+function stupidNth(formula, limit){
+ var a = formula[0],
+ b = formula[1];
+
+ if(a === 0 && b > 0) return [b - 1];
+
+ /*
+ var result = [];
+
+ for(var i = b; a > 0 ? i <= limit : i >= 1; i += a){
+ if(i > 0) result.push(i - 1);
+ }
+
+ return result.sort();
+ */
+
+ //taken from qwery
+ return valArray.filter(function(val){
+ for(var i = b, l = valArray.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a){
+ if(val === valArray[i - 1]) return true;
+ }
+ });
+}
+
+describe("nth-checks", function(){
+ describe("parser", function(){
+ it("parse invalid", parseInvalid);
+ it("parse valid", parseValid);
+ });
+
+ it("check values", testValid);
+});

Powered by Google App Engine
This is Rietveld 408576698