js/src/tests/ecma_5/JSON/parse-crockford-01.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 // Ported from dom/src/json/test/unit/test_decode.js
     3 var str =
     4   '[\n' +
     5   '    "JSON Test Pattern pass1",\n' +
     6   '    {"object with 1 member":["array with 1 element"]},\n' +
     7   '    {},\n' +
     8   '    [],\n' +
     9   '    -42,\n' +
    10   '    true,\n' +
    11   '    false,\n' +
    12   '    null,\n' +
    13   '    {\n' +
    14   '        "integer": 1234567890,\n' +
    15   '        "real": -9876.543210,\n' +
    16   '        "e": 0.123456789e-12,\n' +
    17   '        "E": 1.234567890E+34,\n' +
    18   '        "":  23456789012E66,\n' +
    19   '        "zero": 0,\n' +
    20   '        "one": 1,\n' +
    21   '        "space": " ",\n' +
    22   '        "quote": "\\"",\n' +
    23   '        "backslash": "\\\\",\n' +
    24   '        "controls": "\\b\\f\\n\\r\\t",\n' +
    25   '        "slash": "/ & \\/",\n' +
    26   '        "alpha": "abcdefghijklmnopqrstuvwyz",\n' +
    27   '        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",\n' +
    28   '        "digit": "0123456789",\n' +
    29   '        "0123456789": "digit",\n' +
    30   '        "special": "`1~!@#$%^&*()_+-={\':[,]}|;.</>?",\n' +
    31   '        "hex": "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",\n' +
    32   '        "true": true,\n' +
    33   '        "false": false,\n' +
    34   '        "null": null,\n' +
    35   '        "array":[  ],\n' +
    36   '        "object":{  },\n' +
    37   '        "address": "50 St. James Street",\n' +
    38   '        "url": "http://www.JSON.org/",\n' +
    39   '        "comment": "// /* <!-- --",\n' +
    40   '        "# -- --> */": " ",\n' +
    41   '        " s p a c e d " :[1,2 , 3\n' +
    42   '\n' +
    43   ',\n' +
    44   '\n' +
    45   '4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],\n' +
    46   '        "jsontext": "{\\"object with 1 member\\":[\\"array with 1 element\\"]}",\n' +
    47   '        "quotes": "&#34; \\u0022 %22 0x22 034 &#x22;",\n' +
    48   '        "\\/\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"\n' +
    49   ': "A key can be any string"\n' +
    50   '    },\n' +
    51   '    0.5 ,98.6\n' +
    52   ',\n' +
    53   '99.44\n' +
    54   ',\n' +
    55   '\n' +
    56   '1066,\n' +
    57   '1e1,\n' +
    58   '0.1e1,\n' +
    59   '1e-1,\n' +
    60   '1e00,2e+00,2e-00\n' +
    61   ',"rosebud"]\n';
    63 var x = JSON.parse(str);
    65 assertEq(x[0], "JSON Test Pattern pass1");
    66 assertEq(x[1]["object with 1 member"][0], "array with 1 element");
    67 assertEq(x[2].constructor, Object);
    68 assertEq(x[3].constructor, Array);
    69 assertEq(x[4], -42);
    70 assertEq(x[5], true);
    71 assertEq(x[6], false);
    72 assertEq(x[7], null);
    73 assertEq(x[8].constructor, Object);
    74 assertEq(x[8]["integer"], 1234567890);
    75 assertEq(x[8]["real"], -9876.543210);
    76 assertEq(x[8]["e"], 0.123456789e-12);
    77 assertEq(x[8]["E"], 1.234567890E+34);
    78 assertEq(x[8][""], 23456789012E66);
    79 assertEq(x[8]["zero"], 0);
    80 assertEq(x[8]["one"], 1);
    81 assertEq(x[8]["space"], " ");
    82 assertEq(x[8]["quote"], "\"");
    83 assertEq(x[8]["backslash"], "\\");
    84 assertEq(x[8]["controls"], "\b\f\n\r\t");
    85 assertEq(x[8]["slash"], "/ & /");
    86 assertEq(x[8]["alpha"], "abcdefghijklmnopqrstuvwyz");
    87 assertEq(x[8]["ALPHA"], "ABCDEFGHIJKLMNOPQRSTUVWYZ");
    88 assertEq(x[8]["digit"], "0123456789");
    89 assertEq(x[8]["0123456789"], "digit");
    90 assertEq(x[8]["special"], "`1~!@#$%^&*()_+-={':[,]}|;.</>?");
    91 assertEq(x[8]["hex"], "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A");
    92 assertEq(x[8]["true"], true);
    93 assertEq(x[8]["false"], false);
    94 assertEq(x[8]["null"], null);
    95 assertEq(x[8]["array"].length, 0);
    96 assertEq(x[8]["object"].constructor, Object);
    97 assertEq(x[8]["address"], "50 St. James Street");
    98 assertEq(x[8]["url"], "http://www.JSON.org/");
    99 assertEq(x[8]["comment"], "// /* <!-- --");
   100 assertEq(x[8]["# -- --> */"], " ");
   101 assertEq(x[8][" s p a c e d "].length, 7);
   102 assertEq(x[8]["compact"].length, 7);
   103 assertEq(x[8]["jsontext"], "{\"object with 1 member\":[\"array with 1 element\"]}");
   104 assertEq(x[8]["quotes"], "&#34; \u0022 %22 0x22 034 &#x22;");
   105 assertEq(x[8]["\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"], "A key can be any string");
   106 assertEq(x[9], 0.5);
   107 assertEq(x[10], 98.6);
   108 assertEq(x[11], 99.44);
   109 assertEq(x[12], 1066);
   110 assertEq(x[13], 1e1);
   111 assertEq(x[14], 0.1e1);
   112 assertEq(x[15], 1e-1);
   113 assertEq(x[16], 1e00);
   114 assertEq(x[17], 2e+00);
   115 assertEq(x[18], 2e-00);
   116 assertEq(x[19], "rosebud");
   118 /******************************************************************************/
   120 if (typeof reportCompare === "function")
   121   reportCompare(true, true);
   123 print("Tests complete");

mercurial