summaryrefslogtreecommitdiff
path: root/jstests/aggregation/extras/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/aggregation/extras/utils.js')
-rw-r--r--jstests/aggregation/extras/utils.js253
1 files changed, 126 insertions, 127 deletions
diff --git a/jstests/aggregation/extras/utils.js b/jstests/aggregation/extras/utils.js
index 60081dd56b9..ab91e71b8be 100644
--- a/jstests/aggregation/extras/utils.js
+++ b/jstests/aggregation/extras/utils.js
@@ -4,37 +4,36 @@
function anyEq(al, ar, v) {
if (typeof(v) == 'undefined')
- v = false;
+ v = false;
if (al instanceof Array) {
- if (!(ar instanceof Array)) {
- if (v)
- print('anyEq: ar is not an array ' + ar);
- return false;
- }
-
- if (!arrayEq(al, ar, v)) {
- if (v)
- print('anyEq: arrayEq(al, ar): false; al=' + al + ' ar=' + ar);
- return false;
- }
+ if (!(ar instanceof Array)) {
+ if (v)
+ print('anyEq: ar is not an array ' + ar);
+ return false;
+ }
+
+ if (!arrayEq(al, ar, v)) {
+ if (v)
+ print('anyEq: arrayEq(al, ar): false; al=' + al + ' ar=' + ar);
+ return false;
+ }
} else if (al instanceof Object) {
- if (!(ar instanceof Object)) {
- if (v)
- print('anyEq: ar is not an object ' + ar);
- return false;
- }
-
- if (!documentEq(al, ar, v)) {
- if (v)
- print('anyEq: documentEq(al, ar): false; al=' + al + ' ar=' + ar);
- return false;
- }
- }
- else if (al != ar) {
- if (v)
- print('anyEq: (al != ar): false; al=' + al + ' ar=' + ar);
- return false;
+ if (!(ar instanceof Object)) {
+ if (v)
+ print('anyEq: ar is not an object ' + ar);
+ return false;
+ }
+
+ if (!documentEq(al, ar, v)) {
+ if (v)
+ print('anyEq: documentEq(al, ar): false; al=' + al + ' ar=' + ar);
+ return false;
+ }
+ } else if (al != ar) {
+ if (v)
+ print('anyEq: (al != ar): false; al=' + al + ' ar=' + ar);
+ return false;
}
/* if we got here, they matched */
@@ -48,54 +47,53 @@ function anyEq(al, ar, v) {
*/
function documentEq(dl, dr, v) {
if (typeof(v) == 'undefined')
- v = false;
+ v = false;
/* make sure these are both objects */
if (!(dl instanceof Object)) {
- if (v)
- print('documentEq: dl is not an object ' + dl);
- return false;
+ if (v)
+ print('documentEq: dl is not an object ' + dl);
+ return false;
}
if (!(dr instanceof Object)) {
- if (v)
- print('documentEq: dr is not an object ' + dr);
- return false;
+ if (v)
+ print('documentEq: dr is not an object ' + dr);
+ return false;
}
/* start by checking for all of dl's properties in dr */
- for(var propertyName in dl) {
- /* skip inherited properties */
- if (!dl.hasOwnProperty(propertyName))
- continue;
-
- /* the documents aren't equal if they don't both have the property */
- if (!dr.hasOwnProperty(propertyName)) {
- if (v)
- print('documentEq: dr doesn\'t have property ' + propertyName);
- return false;
- }
-
- /* if the property is the _id, they don't have to be equal */
- if (propertyName == '_id')
- continue;
-
- if (!anyEq(dl[propertyName], dr[propertyName], v)) {
- return false;
- }
+ for (var propertyName in dl) {
+ /* skip inherited properties */
+ if (!dl.hasOwnProperty(propertyName))
+ continue;
+
+ /* the documents aren't equal if they don't both have the property */
+ if (!dr.hasOwnProperty(propertyName)) {
+ if (v)
+ print('documentEq: dr doesn\'t have property ' + propertyName);
+ return false;
+ }
+
+ /* if the property is the _id, they don't have to be equal */
+ if (propertyName == '_id')
+ continue;
+
+ if (!anyEq(dl[propertyName], dr[propertyName], v)) {
+ return false;
+ }
}
/* now make sure that dr doesn't have any extras that dl doesn't have */
- for(var propertyName in dr) {
- if (!dr.hasOwnProperty(propertyName))
- continue;
-
- /* if dl doesn't have this complain; if it does, we compared it above */
- if (!dl.hasOwnProperty(propertyName)) {
- if (v)
- print('documentEq: dl is missing property ' +
- propertyName);
- return false;
- }
+ for (var propertyName in dr) {
+ if (!dr.hasOwnProperty(propertyName))
+ continue;
+
+ /* if dl doesn't have this complain; if it does, we compared it above */
+ if (!dl.hasOwnProperty(propertyName)) {
+ if (v)
+ print('documentEq: dl is missing property ' + propertyName);
+ return false;
+ }
}
/* if we got here, the two documents are an exact match */
@@ -104,35 +102,34 @@ function documentEq(dl, dr, v) {
function arrayEq(al, ar, v) {
if (typeof(v) == 'undefined')
- v = false;
+ v = false;
/* check that these are both arrays */
if (!(al instanceof Array)) {
- if (v)
- print('arrayEq: al is not an array: ' + al);
- return false;
+ if (v)
+ print('arrayEq: al is not an array: ' + al);
+ return false;
}
if (!(ar instanceof Array)) {
- if (v)
- print('arrayEq: ar is not an array: ' + ar);
- return false;
+ if (v)
+ print('arrayEq: ar is not an array: ' + ar);
+ return false;
}
if (al.length != ar.length) {
- if (v)
- print('arrayEq: array lengths do not match: ' + al +
- ', ' + ar);
- return false;
+ if (v)
+ print('arrayEq: array lengths do not match: ' + al + ', ' + ar);
+ return false;
}
var i = 0;
var j = 0;
- while ( i < al.length ) {
- if (anyEq(al[i], ar[j], v) ) {
+ while (i < al.length) {
+ if (anyEq(al[i], ar[j], v)) {
j = 0;
i++;
- } else if ( j < ar.length ) {
+ } else if (j < ar.length) {
j++;
} else {
return false;
@@ -150,8 +147,8 @@ function arrayShallowCopy(a) {
assert(a instanceof Array, 'arrayShallowCopy: argument is not an array');
var c = [];
- for(var i = 0; i < a.length; ++i)
- c.push(a[i]);
+ for (var i = 0; i < a.length; ++i)
+ c.push(a[i]);
return c;
}
@@ -165,46 +162,45 @@ function arrayShallowCopy(a) {
*/
function resultsEq(rl, rr, v) {
if (typeof(v) == 'undefined')
- v = false;
+ v = false;
/* make clones of the arguments so that we don't damage them */
rl = arrayShallowCopy(rl);
rr = arrayShallowCopy(rr);
if (rl.length != rr.length) {
- if (v)
- print('resultsEq: array lengths do not match ' +
- rl + ', ' + rr);
- return false;
+ if (v)
+ print('resultsEq: array lengths do not match ' + rl + ', ' + rr);
+ return false;
}
- for(var i = 0; i < rl.length; ++i) {
- var foundIt = false;
-
- /* find a match in the other array */
- for(var j = 0; j < rr.length; ++j) {
- if (!anyEq(rl[i], rr[j], v))
- continue;
-
- /*
- Because we made the copies above, we can edit these out of the
- arrays so we don't check on them anymore.
-
- For the inner loop, we're going to be skipping out, so we don't
- need to be too careful.
- */
- rr.splice(j, 1);
- foundIt = true;
- break;
- /* TODO */
- }
-
- if (!foundIt) {
- /* if we got here, we didn't find this item */
- if (v)
- print('resultsEq: search target missing index: ' + i);
- return false;
- }
+ for (var i = 0; i < rl.length; ++i) {
+ var foundIt = false;
+
+ /* find a match in the other array */
+ for (var j = 0; j < rr.length; ++j) {
+ if (!anyEq(rl[i], rr[j], v))
+ continue;
+
+ /*
+ Because we made the copies above, we can edit these out of the
+ arrays so we don't check on them anymore.
+
+ For the inner loop, we're going to be skipping out, so we don't
+ need to be too careful.
+ */
+ rr.splice(j, 1);
+ foundIt = true;
+ break;
+ /* TODO */
+ }
+
+ if (!foundIt) {
+ /* if we got here, we didn't find this item */
+ if (v)
+ print('resultsEq: search target missing index: ' + i);
+ return false;
+ }
}
/* if we got here, everything matched */
@@ -214,16 +210,15 @@ function resultsEq(rl, rr, v) {
function orderedArrayEq(al, ar, v) {
if (al.length != ar.length) {
- if (v)
- print('orderedArrayEq: array lengths do not match ' +
- al + ', ' + ar);
- return false;
+ if (v)
+ print('orderedArrayEq: array lengths do not match ' + al + ', ' + ar);
+ return false;
}
/* check the elements in the array */
- for(var i = 0; i < al.length; ++i) {
- if (!anyEq(al[i], ar[i], v))
- return false;
+ for (var i = 0; i < al.length; ++i) {
+ if (!anyEq(al[i], ar[i], v))
+ return false;
}
/* if we got here, everything matched */
@@ -236,7 +231,6 @@ function orderedArrayEq(al, ar, v) {
*/
function assertErrorCode(coll, pipe, code, errmsg) {
-
if (!Array.isArray(pipe)) {
pipe = [pipe];
}
@@ -251,21 +245,26 @@ function assertErrorCode(coll, pipe, code, errmsg) {
assert.eq(res.code, code);
// Test with cursors
- var cmd = {pipeline: pipe};
+ var cmd = {
+ pipeline: pipe
+ };
// cmd.cursor = {};
- cmd.cursor = {batchSize: 0};
+ cmd.cursor = {
+ batchSize: 0
+ };
var cursorRes = coll.runCommand("aggregate", cmd);
if (cursorRes.ok) {
- var followupBatchSize = 0; // default
+ var followupBatchSize = 0; // default
var cursor = new DBCommandCursor(coll.getMongo(), cursorRes, followupBatchSize);
- var error = assert.throws(function(){cursor.itcount();}, [], "expected error: " + code);
+ var error = assert.throws(function() {
+ cursor.itcount();
+ }, [], "expected error: " + code);
if (!error.message.search(code)) {
assert(false, "expected error: " + code + " got: " + error);
}
- }
- else {
+ } else {
assert.eq(cursorRes.code, code);
}
}