From 571dce65a97d95bc782bf455ba1b29e2df03c564 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Wed, 5 Mar 2014 12:43:33 -0800 Subject: [PATCH] Add tests for "index parallel arrays" error --- packages/minimongo/minimongo_tests.js | 20 ++++++++++++++++++++ packages/minimongo/sort.js | 3 +-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js index 0f759afabf..9deb231f97 100644 --- a/packages/minimongo/minimongo_tests.js +++ b/packages/minimongo/minimongo_tests.js @@ -1811,6 +1811,13 @@ Tinytest.add("minimongo - sort keys", function (test) { test.equal(actualKeys, expectedKeys); }; + var testParallelError = function (sortSpec, doc) { + var sorter = new Minimongo.Sorter(sortSpec); + test.throws(function () { + sorter._generateKeysFromDoc(doc, function (){}); + }, /parallel arrays/); + }; + // Just non-array fields. testKeys({'a.x': 1, 'a.y': 1}, {a: {x: 0, y: 5}}, @@ -1831,6 +1838,19 @@ Tinytest.add("minimongo - sort keys", function (test) { testKeys({'a.x': 1, b: -1, 'a.y': 1}, {a: [{x: 0, y: 5}, {x: 1, y: 3}], b: 42}, [[0,42,5], [1,42,3]]); + testKeys({a: 1, b: 1}, + {a: [1, 2, 3], b: 42}, + [[1,42], [2,42], [3,42]]); + + // Don't support multiple arrays at the same level. + testParallelError({a: 1, b: 1}, + {a: [1, 2, 3], b: [42]}); + + // We are MORE STRICT than Mongo here; Mongo supports this! + // XXX support this too #NestedArraySort + testParallelError({'a.x': 1, 'a.y': 1}, + {a: [{x: 1, y: [2, 3]}, + {x: 2, y: [4, 5]}]}); }); Tinytest.add("minimongo - binary search", function (test) { diff --git a/packages/minimongo/sort.js b/packages/minimongo/sort.js index 49a62f9992..faac0a002c 100644 --- a/packages/minimongo/sort.js +++ b/packages/minimongo/sort.js @@ -90,8 +90,6 @@ _.extend(Minimongo.Sorter.prototype, { // you can find along the same paths". ie, for a doc {a: [{x: 0, y: 5}, {x: // 1, y: 3}]} with sort spec {'a.x': 1, 'a.y': 1}, the only keys are [0,5] and // [1,3], and the minimum key is [0,5]; notably, [0,3] is NOT a key. - // - // XXX write direct unit tests for this stuff _getMinKeyFromDoc: function (doc) { var self = this; var minKey = null; @@ -182,6 +180,7 @@ _.extend(Minimongo.Sorter.prototype, { // // (In MongoDB it seems to be OK to have {a: 1, 'a.x.y': 1} where 'a' // and 'a.x.y' are both arrays, but we don't allow this for now. + // #NestedArraySort // XXX achieve full compatibility here if (knownPaths && !_.has(knownPaths, path)) { throw Error("cannot index parallel arrays");