Add tests for "index parallel arrays" error

This commit is contained in:
David Glasser
2014-03-05 12:43:33 -08:00
parent e71027cb23
commit 571dce65a9
2 changed files with 21 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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");