diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js index c8ab90524a..86d397495a 100644 --- a/packages/minimongo/minimongo_tests.js +++ b/packages/minimongo/minimongo_tests.js @@ -520,12 +520,33 @@ Tinytest.add("minimongo - selector_compiler", function (test) { match({x: {$not: /a/}}, {x: "dog"}); nomatch({x: {$not: /a/}}, {x: "cat"}); match({x: {$not: /a/}}, {x: ["dog", "puppy"]}); - nomatch({x: {$not: /a/}}, {x: ["kitten", "cat"]}) + nomatch({x: {$not: /a/}}, {x: ["kitten", "cat"]}); + + // dotted keypaths: bare values + match({"a.b": 1}, {a: {b: 1}}); + nomatch({"a.b": 1}, {a: {b: 2}}); + match({"a.b": [1,2,3]}, {a: {b: [1,2,3]}}); + nomatch({"a.b": [1,2,3]}, {a: {b: [4]}}); + match({"a.b": /a/}, {a: {b: "cat"}}); + nomatch({"a.b": /a/}, {a: {b: "dog"}}); + + // dotted keypaths: literal objects + match({"a.b": {c: 1}}, {a: {b: {c: 1}}}); + nomatch({"a.b": {c: 1}}, {a: {b: {c: 2}}}); + nomatch({"a.b": {c: 1}}, {a: {b: 2}}); + match({"a.b": {c: 1, d: 2}}, {a: {b: {c: 1, d: 2}}}); + nomatch({"a.b": {c: 1, d: 2}}, {a: {b: {c: 1, d: 1}}}); + nomatch({"a.b": {c: 1, d: 2}}, {a: {b: {d: 2}}}); + + // dotted keypaths: $ operators + match({"a.b": {$in: [1, 2, 3]}}, {a: {b: [2]}}); // tested against mongodb + match({"a.b": {$in: [{x: 1}, {x: 2}, {x: 3}]}}, {a: {b: [{x: 2}]}}); + match({"a.b": {$in: [1, 2, 3]}}, {a: {b: [4, 2]}}); + nomatch({"a.b": {$in: [1, 2, 3]}}, {a: {b: [4]}}); // XXX still needs tests: // - $or, $and, $nor, $where // - $elemMatch - // - dotted keypaths // - people.2.name // - non-scalar arguments to $gt, $lt, etc }); diff --git a/packages/minimongo/selector.js b/packages/minimongo/selector.js index 65deedc4af..82255949e0 100644 --- a/packages/minimongo/selector.js +++ b/packages/minimongo/selector.js @@ -356,10 +356,9 @@ LocalCollection._exprForKeypathPredicate = function (keypath, value, literals) { var predcode = ''; if (value instanceof RegExp) { predcode = LocalCollection._exprForOperatorTest(value, literals); - } else if ( - !(typeof value === 'object') || - value === null || - value instanceof Array) { + } else if ( !(typeof value === 'object') + || value === null + || value instanceof Array) { // it's something like {x.y: 12} or {x.y: [12]} predcode = LocalCollection._exprForValueTest(value, literals); } else { @@ -395,7 +394,7 @@ LocalCollection._exprForKeypathPredicate = function (keypath, value, literals) { // for all but the innermost level of a dotted expression, // if the runtime type is an array, search it ret = 'f._matches(' + formal + '[' + JSON.stringify(part) + - '], function(x){return ' + ret + ';}'; + '], function(x){return ' + ret + ';})'; } }