Permalink
Browse files

Simplest fix for lookup with missing variables

1 parent 7e1176c commit 1d04a9515071f8edb3ad8538aa356559ed1eb538 @brainopia brainopia committed Dec 12, 2016
Showing with 68 additions and 0 deletions.
  1. +4 −0 src/runtime/builder.ts
  2. +64 −0 test/join.ts
@@ -299,6 +299,10 @@ function buildScans(block, context, scanLikes, outputScans) {
if(!(entity || attribute || value || node)) {
context.errors.push(errors.blankScan(block, scanLike));
+ } else {
+ entity = entity || context.createVariable();
+ attribute = attribute || context.createVariable();
+ value = value || context.createVariable();
}
let final = new join.Scan(scanLike.id + "|build", entity, attribute, value, node, scanLike.scopes);
View
@@ -2056,6 +2056,70 @@ test("lookup with bound attribute", (assert) => {
assert.end();
})
+test("lookup with missing value", (assert) => {
+ let expected = {
+ insert: [
+ ["a", "tag", "person"],
+ ["a", "name", "chris"],
+ ["b", "tag", "result"],
+ ["b", "record", "a"],
+ ["b", "attribute", "tag"],
+ ["c", "tag", "result"],
+ ["c", "record", "a"],
+ ["c", "attribute", "name"]
+ ],
+ remove: []
+ };
+ evaluate(assert, expected, `
+ prepare data
+ ~~~
+ commit
+ [#person name: "chris"]
+ ~~~
+
+ test
+ ~~~
+ search
+ lookup[record attribute]
+ not(record.tag = "result")
+ commit
+ [#result record attribute]
+ ~~~
+ `);
+ assert.end();
+})
+
+test("lookup with missing record and attribute", (assert) => {
+ let expected = {
+ insert: [
+ ["a", "tag", "result"],
+ ["b", "tag", "person"],
+ ["b", "name", "chris"],
+ ["a", "value", "result"],
+ ["a", "value", "person"],
+ ["a", "value", "chris"]
+ ],
+ remove: []
+ };
+ evaluate(assert, expected, `
+ prepare data
+ ~~~
+ commit
+ [#result]
+ [#person name: "chris"]
+ ~~~
+ test
+ ~~~
+ search
+ lookup[value]
+ result = [#result]
+ commit
+ result.value := value
+ ~~~
+ `);
+ assert.end();
+})
+
test("lookup with free attribute, node and bound value", (assert) => {
let expected = {
insert: [

0 comments on commit 1d04a95

Please sign in to comment.