- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / JSON / JSON-2.59 / t / 18_json_checker.t
1
2 # use the testsuite from http://www.json.org/JSON_checker/
3 # except for fail18.json, as we do not support a depth of 20 (but 16 and 32).
4
5 # copied over from JSON::XS and modified to use JSON
6
7 use strict;
8 #no warnings;
9 local $^W = undef;
10 use Test::More;
11 BEGIN { plan tests => 39 };
12 BEGIN { $ENV{PERL_JSON_BACKEND} = "JSON::backportPP"; }
13
14 use JSON;
15
16 my $json = JSON->new->utf8->max_depth(32)->canonical;
17
18 binmode DATA;
19 my $num = 1;
20 for (;;) {
21
22    $/ = "\n# ";
23    chomp (my $test = <DATA>)
24       or last;
25    $/ = "\n";
26    my $name = <DATA>;
27    if (my $perl = eval { $json->decode ($test) }) {
28       ok ($name =~ /^pass/, $name);
29 #print $json->encode ($perl), "\n";
30       is ($json->encode ($json->decode ($json->encode ($perl))), $json->encode ($perl));
31    } else {
32       ok ($name =~ /^fail/, "$name ($@)");
33    }
34
35 }
36
37 __DATA__
38 "A JSON payload should be an object or array, not a string."
39 # fail1.json
40 {"Extra value after close": true} "misplaced quoted value"
41 # fail10.json
42 {"Illegal expression": 1 + 2}
43 # fail11.json
44 {"Illegal invocation": alert()}
45 # fail12.json
46 {"Numbers cannot have leading zeroes": 013}
47 # fail13.json
48 {"Numbers cannot be hex": 0x14}
49 # fail14.json
50 ["Illegal backslash escape: \x15"]
51 # fail15.json
52 [\naked]
53 # fail16.json
54 ["Illegal backslash escape: \017"]
55 # fail17.json
56 [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
57 # fail18.json
58 {"Missing colon" null}
59 # fail19.json
60 ["Unclosed array"
61 # fail2.json
62 {"Double colon":: null}
63 # fail20.json
64 {"Comma instead of colon", null}
65 # fail21.json
66 ["Colon instead of comma": false]
67 # fail22.json
68 ["Bad value", truth]
69 # fail23.json
70 ['single quote']
71 # fail24.json
72 ["      tab     character       in      string  "]
73 # fail25.json
74 ["tab\   character\   in\  string\  "]
75 # fail26.json
76 ["line
77 break"]
78 # fail27.json
79 ["line\
80 break"]
81 # fail28.json
82 [0e]
83 # fail29.json
84 {unquoted_key: "keys must be quoted"}
85 # fail3.json
86 [0e+]
87 # fail30.json
88 [0e+-1]
89 # fail31.json
90 {"Comma instead if closing brace": true,
91 # fail32.json
92 ["mismatch"}
93 # fail33.json
94 ["extra comma",]
95 # fail4.json
96 ["double extra comma",,]
97 # fail5.json
98 [   , "<-- missing value"]
99 # fail6.json
100 ["Comma after the close"],
101 # fail7.json
102 ["Extra close"]]
103 # fail8.json
104 {"Extra comma": true,}
105 # fail9.json
106 [
107     "JSON Test Pattern pass1",
108     {"object with 1 member":["array with 1 element"]},
109     {},
110     [],
111     -42,
112     true,
113     false,
114     null,
115     {
116         "integer": 1234567890,
117         "real": -9876.543210,
118         "e": 0.123456789e-12,
119         "E": 1.234567890E+34,
120         "":  23456789012E66,
121         "zero": 0,
122         "one": 1,
123         "space": " ",
124         "quote": "\"",
125         "backslash": "\\",
126         "controls": "\b\f\n\r\t",
127         "slash": "/ & \/",
128         "alpha": "abcdefghijklmnopqrstuvwyz",
129         "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
130         "digit": "0123456789",
131         "0123456789": "digit",
132         "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
133         "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
134         "true": true,
135         "false": false,
136         "null": null,
137         "array":[  ],
138         "object":{  },
139         "address": "50 St. James Street",
140         "url": "http://www.JSON.org/",
141         "comment": "// /* <!-- --",
142         "# -- --> */": " ",
143         " s p a c e d " :[1,2 , 3
144
145 ,
146
147 4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],
148         "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
149         "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
150         "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
151 : "A key can be any string"
152     },
153     0.5 ,98.6
154 ,
155 99.44
156 ,
157
158 1066,
159 1e1,
160 0.1e1,
161 1e-1,
162 1e00,2e+00,2e-00
163 ,"rosebud"]
164 # pass1.json
165 [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
166 # pass2.json
167 {
168     "JSON Test Pattern pass3": {
169         "The outermost value": "must be an object or array.",
170         "In this test": "It is an object."
171     }
172 }
173
174 # pass3.json