From 129154695455282a2013ed33c64a0785c7c491db Mon Sep 17 00:00:00 2001 From: Christian Schramm Date: Fri, 16 Nov 2012 16:11:23 +0100 Subject: [PATCH] Added $where tests --- packages/minimongo/minimongo_tests.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js index d7152718b8..6c790a569a 100644 --- a/packages/minimongo/minimongo_tests.js +++ b/packages/minimongo/minimongo_tests.js @@ -590,6 +590,9 @@ Tinytest.add("minimongo - selector_compiler", function (test) { nomatch({$or: [{a: 1}, {b: 2}]}, {c: [1, 2, 3]}); nomatch({$or: [{a: 1}, {b: 2}]}, {a: [2, 3, 4]}); match({$or: [{a: 1}, {a: 2}]}, {a: 1}); + match({$or: [{a: 1}, {a: 2}], b: 2}, {a: 1, b: 2}); + nomatch({$or: [{a: 2}, {a: 3}], b: 2}, {a: 1, b: 2}); + nomatch({$or: [{a: 1}, {a: 2}], b: 3}, {a: 1, b: 2}); // $or and $lt, $lte, $gt, $gte match({$or: [{a: {$lte: 1}}, {a: 2}]}, {a: 1}); @@ -734,6 +737,8 @@ Tinytest.add("minimongo - selector_compiler", function (test) { nomatch({$and: [{a: 1}, {b: 1}]}, {a: 1}); match({$and: [{a: 1}, {b: 2}]}, {a: 1, b: 2}); nomatch({$and: [{a: 1}, {b: 1}]}, {a: 1, b: 2}); + match({$and: [{a: 1}, {b: 2}], c: 3}, {a: 1, b: 2, c: 3}); + nomatch({$and: [{a: 1}, {b: 2}], c: 4}, {a: 1, b: 2, c: 3}); // $and and regexes match({$and: [{a: /a/}]}, {a: "cat"}); @@ -801,8 +806,16 @@ Tinytest.add("minimongo - selector_compiler", function (test) { match({$and: [{a: {$not: {$lt: 0}}}, {a: {$not: {$gt: 2}}}]}, {a: 1}); nomatch({$and: [{a: {$not: {$lt: 2}}}, {a: {$not: {$gt: 0}}}]}, {a: 1}); + // $where + match({$where: "this.a === 1"}, {a: 1}); + nomatch({$where: "this.a !== 1"}, {a: 1}); + nomatch({$where: "this.a === 1", a: 2}, {a: 1}); + match({$where: "this.a === 1", b: 2}, {a: 1, b: 2}); + match({$where: "this.a === 1 && this.b === 2"}, {a: 1, b: 2}); + match({$where: "Array.isArray(this.a)"}, {a: []}); + nomatch({$where: "Array.isArray(this.a)"}, {a: 1}); + // XXX still needs tests: - // - $where // - $elemMatch // - people.2.name // - non-scalar arguments to $gt, $lt, etc