Skip to content
Permalink
Browse files

feat(jexl): add "interesects" binary operator (#176)

  • Loading branch information...
czosel committed May 1, 2019
1 parent 2d1f490 commit 502c747906a9ecacfbd0ceb06960da454814dbf6
Showing with 19 additions and 0 deletions.
  1. +3 −0 addon/lib/document.js
  2. +16 −0 tests/unit/lib/document-test.js
@@ -72,6 +72,9 @@ export default EmberObject.extend({
questionJexl.addTransform("answer", slugWithPath =>
this.findAnswer(slugWithPath)
);
questionJexl.addBinaryOp("intersects", 20, (left, right) =>
left.some(val => right.includes(val))
);

return questionJexl;
}),
@@ -125,4 +125,20 @@ module("Unit | Library | document", function(hooks) {
"foobar"
);
});

test("question jexl intersects operator", async function(assert) {
const tests = [
["[1,2] intersects [2,3]", true],
["[1,2] intersects [3,4]", false],
["[] intersects []", false],
["[1] intersects []", false],
["['foo'] intersects ['bar', 'bazz']", false],
["['foo'] intersects ['foo', 'foo']", true],
["[1] intersects [1] && [2] intersects [2]", true],
["[2] intersects [1] + [2]", true]
];
for (let [expression, result] of tests) {
assert.equal(await this.document.questionJexl.eval(expression), result);
}
});
});

0 comments on commit 502c747

Please sign in to comment.
You can’t perform that action at this time.