michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: var gTestfile = 'stringify-gap.js'; michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 584909; michael@0: var summary = michael@0: "JSON.stringify(_1, _2, numberGreaterThanOne) produces wrong output"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var LF = "\n"; michael@0: var GAP = " "; michael@0: michael@0: var obj = { a: { b: [1, 2], c: { d: 3, e: 4 }, f: [], g: {}, h: [5], i: { j: 6 } } }; michael@0: michael@0: var expected = michael@0: '{\n' + michael@0: ' "a": {\n' + michael@0: ' "b": [\n' + michael@0: ' 1,\n' + michael@0: ' 2\n' + michael@0: ' ],\n' + michael@0: ' "c": {\n' + michael@0: ' "d": 3,\n' + michael@0: ' "e": 4\n' + michael@0: ' },\n' + michael@0: ' "f": [],\n' + michael@0: ' "g": {},\n' + michael@0: ' "h": [\n' + michael@0: ' 5\n' + michael@0: ' ],\n' + michael@0: ' "i": {\n' + michael@0: ' "j": 6\n' + michael@0: ' }\n' + michael@0: ' }\n' + michael@0: '}'; michael@0: michael@0: assertEq(JSON.stringify(obj, null, 3), expected); michael@0: assertEq(JSON.stringify(obj, null, " "), expected); michael@0: michael@0: obj = [1, 2, 3]; michael@0: michael@0: String.prototype.toString = function() { return "--"; }; michael@0: michael@0: assertEq(JSON.stringify(obj, null, new String(" ")), "[\n--1,\n--2,\n--3\n]"); michael@0: michael@0: Number.prototype.valueOf = function() { return 0; }; michael@0: michael@0: assertEq(JSON.stringify(obj, null, new Number(3)), "[1,2,3]"); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("All tests passed!");