diff options
author | Benjamin Murphy <benjamin_murphy@me.com> | 2016-03-17 15:21:48 -0400 |
---|---|---|
committer | Benjamin Murphy <benjamin_murphy@me.com> | 2016-03-25 10:37:50 -0400 |
commit | 5afa97da4ce5049ef7eb8bf4717ce37bd6777754 (patch) | |
tree | 94f9cf0e1581f914ac26c8907a93030dd07c570d /jstests | |
parent | 10b650835a78fbf7ebe9cf26926cc45556efd178 (diff) | |
download | mongo-5afa97da4ce5049ef7eb8bf4717ce37bd6777754.tar.gz |
SERVER-22580 Aggregation now supports substrCP.
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/aggregation/bugs/server22580.js | 43 | ||||
-rw-r--r-- | jstests/aggregation/bugs/server6556.js | 9 | ||||
-rw-r--r-- | jstests/aggregation/bugs/substr.js | 39 | ||||
-rw-r--r-- | jstests/aggregation/testall.js | 2 |
4 files changed, 70 insertions, 23 deletions
diff --git a/jstests/aggregation/bugs/server22580.js b/jstests/aggregation/bugs/server22580.js new file mode 100644 index 00000000000..afbfdd00dcd --- /dev/null +++ b/jstests/aggregation/bugs/server22580.js @@ -0,0 +1,43 @@ +// In SERVER-22580, the $substrCP expression was introduced. In this file, we test the error cases +// of this expression. +load("jstests/aggregation/extras/utils.js"); // For assertErrorCode. + +(function() { + "use strict"; + + var coll = db.substrCP; + coll.drop(); + + // Need an empty document for pipeline. + coll.insert({}); + + assertErrorCode(coll, + [{$project: {substr: {$substrCP: ["abc", 0, "a"]}}}], + 34452, + "$substrCP" + " does not accept non-numeric types as a length."); + + assertErrorCode(coll, + [{$project: {substr: {$substrCP: ["abc", 0, NaN]}}}], + 34453, + "$substrCP" + " does not accept non-integers as a length."); + + assertErrorCode(coll, + [{$project: {substr: {$substrCP: ["abc", "abc", 3]}}}], + 34450, + "$substrCP does not accept non-numeric types as a starting index."); + + assertErrorCode(coll, + [{$project: {substr: {$substrCP: ["abc", 2.2, 3]}}}], + 34451, + "$substrCP" + " does not accept non-integers as a starting index."); + + assertErrorCode(coll, + [{$project: {substr: {$substrCP: ["abc", -1, 3]}}}], + 34455, + "$substrCP " + "does not accept negative integers as inputs."); + + assertErrorCode(coll, + [{$project: {substr: {$substrCP: ["abc", 1, -3]}}}], + 34454, + "$substrCP " + "does not accept negative integers as inputs."); +}()); diff --git a/jstests/aggregation/bugs/server6556.js b/jstests/aggregation/bugs/server6556.js index 721b9fd5a98..636bef6b02c 100644 --- a/jstests/aggregation/bugs/server6556.js +++ b/jstests/aggregation/bugs/server6556.js @@ -9,8 +9,9 @@ c.save({foo: "as\0df"}); assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as\0df", "$foo"]}}}).toArray(), [{matches: true}]); // compare with the substring containing only the up to the null, they should not match -assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as\0df", {$substr: ["$foo", 0, 3]}]}}}) - .toArray(), +assert.eq(c.aggregate({ + $project: {_id: 0, matches: {$eq: ["as\0df", {$substrBytes: ["$foo", 0, 3]}]}} +}).toArray(), [{matches: false}]); // partial the other way shouldnt work either assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as", "$foo"]}}}).toArray(), @@ -19,6 +20,4 @@ assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as", "$foo"]}}}).toAr assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as\0de", "$foo"]}}}).toArray(), [{matches: false}]); // should assert on fieldpaths with a null -assert.throws(function() { - c.aggregate({$project: {_id: 0, matches: {$eq: ["as\0df", "$f\0oo"]}}}); -}); +assert.throws(c.aggregate, {$project: {_id: 0, matches: {$eq: ["as\0df", "$f\0oo"]}}}); diff --git a/jstests/aggregation/bugs/substr.js b/jstests/aggregation/bugs/substr.js index 4aee531dd67..9b514eb4679 100644 --- a/jstests/aggregation/bugs/substr.js +++ b/jstests/aggregation/bugs/substr.js @@ -1,4 +1,4 @@ -// Aggregation $substr tests. +// Aggregation $substrBytes tests. t = db.jstests_aggregation_substr; t.drop(); @@ -6,11 +6,12 @@ t.drop(); t.save({}); function assertSubstring(expected, str, offset, len) { - assert.eq(expected, t.aggregate({$project: {a: {$substr: [str, offset, len]}}}).toArray()[0].a); + assert.eq(expected, + t.aggregate({$project: {a: {$substrBytes: [str, offset, len]}}}).toArray()[0].a); } function assertArgsException(args) { - assert.commandFailed(t.runCommand('aggregate', {pipeline: [{$substr: args}]})); + assert.commandFailed(t.runCommand('aggregate', {pipeline: [{$substrBytes: args}]})); } function assertException(str, offset, len) { @@ -104,17 +105,21 @@ assertSubstring('cde', '$z', {$add: ['$b', '$b']}, {$add: ['$c', '$d']}); assertSubstring('cde', '$z', {$add: ['$b', 1]}, {$add: [2, '$d']}); // Nested. -assert.eq('e', - t.aggregate({ - $project: { - a: { - $substr: [ - {$substr: [{$substr: [{$substr: ['abcdefghij', 1, 6]}, 2, 5]}, 0, 3]}, - 1, - 1 - ] - } - } - }) - .toArray()[0] - .a); +assert.eq( + 'e', + t.aggregate({ + $project: { + a: { + $substrBytes: [ + { + $substrBytes: + [{$substrBytes: [{$substrBytes: ['abcdefghij', 1, 6]}, 2, 5]}, 0, 3] + }, + 1, + 1 + ] + } + } + }) + .toArray()[0] + .a); diff --git a/jstests/aggregation/testall.js b/jstests/aggregation/testall.js index 11f2936abfc..5771cbefaef 100644 --- a/jstests/aggregation/testall.js +++ b/jstests/aggregation/testall.js @@ -474,7 +474,7 @@ var p17 = db.runCommand({ aggregate: "article", pipeline: [{ $project: { - author: {$substr: ["$author", 1, 2]}, + author: {$substrBytes: ["$author", 1, 2]}, } }] }); |