js/src/tests/ecma_5/JSON/parse-primitives.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:0d5468300f86
1 // Ported from dom/src/json/test/unit/test_decode_primitives.js
2
3 var x;
4
5 // check an empty object, just for sanity
6 var emptyObject = "{}";
7 x = JSON.parse(emptyObject);
8 assertEq(typeof x, "object");
9 assertEq(x instanceof Object, true);
10
11 x = JSON.parse(emptyObject);
12 assertEq(typeof x, "object");
13
14 // booleans and null
15 x = JSON.parse("true");
16 assertEq(x, true);
17
18 x = JSON.parse("true ");
19 assertEq(x, true);
20
21 x = JSON.parse("false");
22 assertEq(x, false);
23
24 x = JSON.parse(" null ");
25 assertEq(x, null);
26
27 // numbers
28 x = JSON.parse("1234567890");
29 assertEq(x, 1234567890);
30
31 x = JSON.parse("-9876.543210");
32 assertEq(x, -9876.543210);
33
34 x = JSON.parse("0.123456789e-12");
35 assertEq(x, 0.123456789e-12);
36
37 x = JSON.parse("1.234567890E+34");
38 assertEq(x, 1.234567890E+34);
39
40 x = JSON.parse(" 23456789012E66 \r\r\r\r \n\n\n\n ");
41 assertEq(x, 23456789012E66);
42
43 // strings
44 x = JSON.parse('"foo"');
45 assertEq(x, "foo");
46
47 x = JSON.parse('"\\r\\n"');
48 assertEq(x, "\r\n");
49
50 x = JSON.parse(' "\\uabcd\uef4A"');
51 assertEq(x, "\uabcd\uef4A");
52
53 x = JSON.parse('"\\uabcd" ');
54 assertEq(x, "\uabcd");
55
56 x = JSON.parse('"\\f"');
57 assertEq(x, "\f");
58
59 /******************************************************************************/
60
61 if (typeof reportCompare === "function")
62 reportCompare(true, true);
63
64 print("Tests complete");

mercurial