summaryrefslogtreecommitdiff
path: root/jstests/decimal/decimal128_test6.js
blob: 63bf6ea92efbea12dd92df74368a127c20e7660b (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
/**
 * Derived from test cases at https://github.com/mongodb/specifications
 */

(function() {
    "use strict";

    var parseErrors = [
        {"description": "Incomplete Exponent", "string": "1e"},
        {"description": "Exponent at the beginning", "string": "E01"},
        {"description": "Just a decimal place", "string": "."},
        {"description": "2 decimal places", "string": "..3"},
        {"description": "2 decimal places", "string": ".13.3"},
        {"description": "2 decimal places", "string": "1..3"},
        {"description": "2 decimal places", "string": "1.3.4"},
        {"description": "2 decimal places", "string": "1.34."},
        {"description": "Decimal with no digits", "string": ".e"},
        {"description": "2 signs", "string": "+-32.4"},
        {"description": "2 signs", "string": "-+32.4"},
        {"description": "2 negative signs", "string": "--32.4"},
        {"description": "2 negative signs", "string": "-32.-4"},
        {"description": "End in negative sign", "string": "32.0-"},
        {"description": "2 negative signs", "string": "32.4E--21"},
        {"description": "2 negative signs", "string": "32.4E-2-1"},
        {"description": "2 signs", "string": "32.4E+-21"},
        {"description": "Empty string", "string": ""},
        {"description": "leading white space positive number", "string": " 1"},
        {"description": "leading white space negative number", "string": " -1"},
        {"description": "trailing white space", "string": "1 "},
        {"description": "Invalid", "string": "E"},
        {"description": "Invalid", "string": "invalid"},
        {"description": "Invalid", "string": "i"},
        {"description": "Invalid", "string": "in"},
        {"description": "Invalid", "string": "-in"},
        {"description": "Invalid", "string": "Na"},
        {"description": "Invalid", "string": "-Na"},
        {"description": "Invalid", "string": "1.23abc"},
        {"description": "Invalid", "string": "1.23abcE+02"},
        {"description": "Invalid", "string": "1.23E+0aabs2"}
    ];

    parseErrors.forEach(function(testCase) {
        print(`Test - ${testCase.description}`);
        function test() {
            NumberDecimal(testCase.string);
        }
        assert.throws(test, [], `[Test - ${testCase.description}] should have failed with error.`);
    });
}());