summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs/server22580.js
blob: 3b9f81dbcfc0b5d85e61851d8d04169f7ea92c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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.");
}());