-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
79 lines (75 loc) · 1.74 KB
/
test.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var MYJSON = require('./json.js');
var assert = require('assert');
var objCheck = function (testCase) {
var string = JSON.stringify(testCase);
assert.deepEqual(MYJSON.parse(string), testCase);
};
var strCheck = function (string) {
var shouldBe;
try {
shouldBe = JSON.parse(string);
} catch (e) {
throw new Error ("invalid test case" + string);
}
assert.deepEqual(MYJSON.parse(string), shouldBe);
}
var strCheckShouldFail = function (string) {
try {
MYJSON.parse(string);
} catch (e) {
return;
}
throw new Error('test should fail');
}
objCheck(1);
objCheck(12);
objCheck(123423);
objCheck(123423.4);
objCheck(-123423.4);
strCheckShouldFail("");
strCheck("null");
strCheck("true");
strCheck("false");
strCheck("\"\"");
strCheck("\"a\"");
strCheck("\"bla-bla-bla\"");
strCheck("\"bla\\\"-bla-bla\"");
objCheck(null);
objCheck(false);
objCheck(true);
objCheck("zzzdwerw");
objCheck("wqe\\qwer");
objCheck("wqe\"rqwer");
objCheck("wqe\\rqwer");
objCheck("wqe\\\"rqwer");
objCheck("wqe\\\\\"rqwer");
objCheck("wqe\\\\rqwer");
objCheck({});
objCheck([]);
objCheck(["234"]);
objCheck(["234", "567"]);
objCheck(["234", "567", null, false]);
objCheck(["234", "567", null, false]);
objCheck([true, "234", "567", null, false]);
objCheck([[]]);
objCheck([1, 3, "sss"]);
objCheck([[[[]]]]);
objCheck([{}])
objCheck({});
objCheck({a: "b"});
objCheck({a: 5});
objCheck({a: 5, b: null});
objCheck({a: "b", d: null});
objCheck({a: "b", d: null, e: []});
objCheck({a: "b", d: null, e: [{}]});
strCheck("[ ]");
strCheck("[ ]");
strCheck("[ ]");
strCheck("[\n]");
strCheck("[\n\tnull ]");
strCheck("[\n\t\"sdf\" , \"zzz\" ]");
strCheck("{}");
strCheck("{ }");
strCheck("{ }");
strCheck("{\"a\" : \"b\" }");
strCheck("{\"a\" : \"b\" , \"c\": null }");