summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs/server20169.js
blob: 27995b8030cd7e1d48ca0a9d5386f5d5f6fb05db (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
49
50
51
52
53
54
55
56
57
58
59
60
61
// In SERVER-20169, the $range expression was added to the aggregation framework. In this file, we
// test the behavior and error cases of this expression.
load("jstests/aggregation/extras/utils.js");  // For assertErrorCode.

(function() {
    "use strict";

    var coll = db.range;
    coll.drop();

    // We need an input document to receive an output document.
    coll.insert({});

    var rangeObj = [1];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    28667,
                    "range requires two" + " or three arguments");

    rangeObj = ["a", 1];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34443,
                    "range requires a" + " numeric starting value");

    rangeObj = [1.1, 1];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34444,
                    "range requires an" + " integral starting value");

    rangeObj = [1, "a"];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34445,
                    "range requires a" + " numeric ending value");

    rangeObj = [1, 1.1];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34446,
                    "range requires an" + " integral ending value");

    rangeObj = [1, 3, "a"];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34447,
                    "range requires a" + " numeric step value");

    rangeObj = [1, 3, 1.1];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34448,
                    "range requires an" + " integral step value");

    rangeObj = [1, 3, 0];
    assertErrorCode(coll,
                    [{$project: {range: {$range: rangeObj}}}],
                    34449,
                    "range requires a" + " non-zero step value");
}());