1 | BEGIN { $| = 1; print "1..7\n"; } |
1 | BEGIN { $| = 1; print "1..8\n"; } |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use JSON::XS; |
4 | use JSON::XS; |
5 | |
5 | |
6 | our $test; |
6 | our $test; |
… | |
… | |
8 | print $_[0] ? "" : "not ", "ok ", ++$test, "\n"; |
8 | print $_[0] ? "" : "not ", "ok ", ++$test, "\n"; |
9 | } |
9 | } |
10 | |
10 | |
11 | my $json = JSON::XS->new->relaxed; |
11 | my $json = JSON::XS->new->relaxed; |
12 | |
12 | |
13 | ok ('[1,2,3]' eq to_json $json->decode (' [1,2, 3]')); |
13 | ok ('[1,2,3]' eq encode_json $json->decode (' [1,2, 3]')); |
14 | ok ('[1,2,4]' eq to_json $json->decode ('[1,2, 4 , ]')); |
14 | ok ('[1,2,4]' eq encode_json $json->decode ('[1,2, 4 , ]')); |
15 | ok (!eval { $json->decode ('[1,2, 3,4,,]') }); |
15 | ok (!eval { $json->decode ('[1,2, 3,4,,]') }); |
16 | ok (!eval { $json->decode ('[,1]') }); |
16 | ok (!eval { $json->decode ('[,1]') }); |
17 | |
17 | |
18 | ok ('{"1":2}' eq to_json $json->decode (' {"1":2}')); |
18 | ok ('{"1":2}' eq encode_json $json->decode (' {"1":2}')); |
19 | ok ('{"1":2}' eq to_json $json->decode ('{"1":2,}')); |
19 | ok ('{"1":2}' eq encode_json $json->decode ('{"1":2,}')); |
20 | ok (!eval { $json->decode ('{,}') }); |
20 | ok (!eval { $json->decode ('{,}') }); |
21 | |
21 | |
|
|
22 | ok ('[1,2]' eq encode_json $json->decode ("[1#,2\n ,2,# ] \n\t]")); |