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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial