js/src/tests/ecma_5/JSON/stringify-gap.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:b6b82f61c95e
1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/licenses/publicdomain/
3
4 var gTestfile = 'stringify-gap.js';
5 //-----------------------------------------------------------------------------
6 var BUGNUMBER = 584909;
7 var summary =
8 "JSON.stringify(_1, _2, numberGreaterThanOne) produces wrong output";
9
10 print(BUGNUMBER + ": " + summary);
11
12 /**************
13 * BEGIN TEST *
14 **************/
15
16 var LF = "\n";
17 var GAP = " ";
18
19 var obj = { a: { b: [1, 2], c: { d: 3, e: 4 }, f: [], g: {}, h: [5], i: { j: 6 } } };
20
21 var expected =
22 '{\n' +
23 ' "a": {\n' +
24 ' "b": [\n' +
25 ' 1,\n' +
26 ' 2\n' +
27 ' ],\n' +
28 ' "c": {\n' +
29 ' "d": 3,\n' +
30 ' "e": 4\n' +
31 ' },\n' +
32 ' "f": [],\n' +
33 ' "g": {},\n' +
34 ' "h": [\n' +
35 ' 5\n' +
36 ' ],\n' +
37 ' "i": {\n' +
38 ' "j": 6\n' +
39 ' }\n' +
40 ' }\n' +
41 '}';
42
43 assertEq(JSON.stringify(obj, null, 3), expected);
44 assertEq(JSON.stringify(obj, null, " "), expected);
45
46 obj = [1, 2, 3];
47
48 String.prototype.toString = function() { return "--"; };
49
50 assertEq(JSON.stringify(obj, null, new String(" ")), "[\n--1,\n--2,\n--3\n]");
51
52 Number.prototype.valueOf = function() { return 0; };
53
54 assertEq(JSON.stringify(obj, null, new Number(3)), "[1,2,3]");
55
56 /******************************************************************************/
57
58 if (typeof reportCompare === "function")
59 reportCompare(true, true);
60
61 print("All tests passed!");

mercurial