Skip to content

Commit

Permalink
Update test framework [fixes npm audit] (#104)
Browse files Browse the repository at this point in the history
* efficiency: short-circuit some and none, fewer not needed intermediate objects

* update test framework
  • Loading branch information
panzi authored Jan 10, 2022
1 parent c1dd82f commit 045a7fd
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 302 deletions.
18 changes: 0 additions & 18 deletions gulpfile.js

This file was deleted.

34 changes: 26 additions & 8 deletions logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html
var current;
var scopedLogic;
var scopedData;
var filtered;
var initial;

// easy syntax for unary operators, like {"var" : "x"} instead of strict {"var" : ["x"]}
Expand Down Expand Up @@ -314,7 +313,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
scopedData = jsonLogic.apply(values[0], data);
scopedLogic = values[1];
// All of an empty set is false. Note, some and none have correct fallback after the for loop
if ( ! scopedData.length) {
if ( ! Array.isArray(scopedData) || ! scopedData.length) {
return false;
}
for (i=0; i < scopedData.length; i+=1) {
Expand All @@ -324,11 +323,31 @@ http://ricostacruz.com/cheatsheets/umdjs.html
}
return true; // All were truthy
} else if (op === "none") {
filtered = jsonLogic.apply({filter: values}, data);
return filtered.length === 0;
scopedData = jsonLogic.apply(values[0], data);
scopedLogic = values[1];

if ( ! Array.isArray(scopedData) || ! scopedData.length) {
return true;
}
for (i=0; i < scopedData.length; i+=1) {
if ( jsonLogic.truthy( jsonLogic.apply(scopedLogic, scopedData[i]) )) {
return false; // First truthy, short circuit
}
}
return true; // None were truthy
} else if (op === "some") {
filtered = jsonLogic.apply({filter: values}, data);
return filtered.length > 0;
scopedData = jsonLogic.apply(values[0], data);
scopedLogic = values[1];

if ( ! Array.isArray(scopedData) || ! scopedData.length) {
return false;
}
for (i=0; i < scopedData.length; i+=1) {
if ( jsonLogic.truthy( jsonLogic.apply(scopedLogic, scopedData[i]) )) {
return true; // First truthy, short circuit
}
}
return false; // None were truthy
}

// Everyone else gets immediate depth-first recursion
Expand All @@ -346,7 +365,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html
var sub_ops = String(op).split(".");
var operation = operations;
for (i = 0; i < sub_ops.length; i++) {

if (!operation.hasOwnProperty(sub_ops[i])) {
throw new Error("Unrecognized operation " + op +
" (failed at " + sub_ops.slice(0, i+1).join(".") + ")");
Expand Down Expand Up @@ -377,7 +395,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
collection.push(values[0]);
} else {
// Recursion!
values.map(function(val) {
values.forEach(function(val) {
collection.push.apply(collection, jsonLogic.uses_data(val) );
});
}
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
"directories": {
"test": "tests"
},
"dependencies": {},
"devDependencies": {
"eslint": "^7.11.0",
"eslint": "^7.32.0",
"eslint-config-google": "^0.14.0",
"gulp": "^3.9.0",
"qunit": "^0.7.7",
"request": "^2.65.0"
"qunit": "^2.16.0"
},
"scripts": {
"test": "gulp test"
"test": "qunit ./tests/tests.js"
},
"repository": {
"type": "git",
Expand Down
17 changes: 0 additions & 17 deletions tests/testrunner.js

This file was deleted.

Loading

0 comments on commit 045a7fd

Please sign in to comment.