ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/18_json_checker.t
Revision: 1.1
Committed: Wed Oct 10 17:38:47 2007 UTC (16 years, 8 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-2_01, rel-1_51, rel-1_53, rel-2_222, rel-3_0, rel-2_2, rel-2_3, rel-2_0, rel-2_1, rel-2_34, rel-2_32, rel-2_33, rel-2_31, rel-2_2311, rel-3_01, rel-3_02, rel-3_03, rel-3_04, rel-2_232, rel-2_231, rel-2_29, rel-2_28, rel-2_21, rel-2_2222, rel-2_23, rel-2_22, rel-2_25, rel-2_24, rel-2_27, rel-2_26
Log Message:
*** empty log message ***

File Contents

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