michael@0: // Ported from dom/src/json/test/unit/test_decode_primitives.js michael@0: michael@0: var x; michael@0: michael@0: // check an empty object, just for sanity michael@0: var emptyObject = "{}"; michael@0: x = JSON.parse(emptyObject); michael@0: assertEq(typeof x, "object"); michael@0: assertEq(x instanceof Object, true); michael@0: michael@0: x = JSON.parse(emptyObject); michael@0: assertEq(typeof x, "object"); michael@0: michael@0: // booleans and null michael@0: x = JSON.parse("true"); michael@0: assertEq(x, true); michael@0: michael@0: x = JSON.parse("true "); michael@0: assertEq(x, true); michael@0: michael@0: x = JSON.parse("false"); michael@0: assertEq(x, false); michael@0: michael@0: x = JSON.parse(" null "); michael@0: assertEq(x, null); michael@0: michael@0: // numbers michael@0: x = JSON.parse("1234567890"); michael@0: assertEq(x, 1234567890); michael@0: michael@0: x = JSON.parse("-9876.543210"); michael@0: assertEq(x, -9876.543210); michael@0: michael@0: x = JSON.parse("0.123456789e-12"); michael@0: assertEq(x, 0.123456789e-12); michael@0: michael@0: x = JSON.parse("1.234567890E+34"); michael@0: assertEq(x, 1.234567890E+34); michael@0: michael@0: x = JSON.parse(" 23456789012E66 \r\r\r\r \n\n\n\n "); michael@0: assertEq(x, 23456789012E66); michael@0: michael@0: // strings michael@0: x = JSON.parse('"foo"'); michael@0: assertEq(x, "foo"); michael@0: michael@0: x = JSON.parse('"\\r\\n"'); michael@0: assertEq(x, "\r\n"); michael@0: michael@0: x = JSON.parse(' "\\uabcd\uef4A"'); michael@0: assertEq(x, "\uabcd\uef4A"); michael@0: michael@0: x = JSON.parse('"\\uabcd" '); michael@0: assertEq(x, "\uabcd"); michael@0: michael@0: x = JSON.parse('"\\f"'); michael@0: assertEq(x, "\f"); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");