ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/03_types.t
Revision: 1.3
Committed: Thu Mar 29 02:45:49 2007 UTC (17 years, 3 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_11, rel-1_1, rel-1_0, rel-1_2, rel-1_01, rel-1_21, rel-1_22
Changes since 1.2: +7 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..19\n"; }
2
3 use utf8;
4 use JSON::XS;
5
6 our $test;
7 sub ok($) {
8 print $_[0] ? "" : "not ", "ok ", ++$test, "\n";
9 }
10
11 ok (!defined JSON::XS->new->allow_nonref (1)->decode ('null'));
12 ok (JSON::XS->new->allow_nonref (1)->decode ('true') == 1);
13 ok (JSON::XS->new->allow_nonref (1)->decode ('false') == 0);
14
15 ok (JSON::XS->new->allow_nonref (1)->decode ('5') == 5);
16 ok (JSON::XS->new->allow_nonref (1)->decode ('-5') == -5);
17 ok (JSON::XS->new->allow_nonref (1)->decode ('5e1') == 50);
18 ok (JSON::XS->new->allow_nonref (1)->decode ('-333e+0') == -333);
19 ok (JSON::XS->new->allow_nonref (1)->decode ('2.5') == 2.5);
20
21 ok (JSON::XS->new->allow_nonref (1)->decode ('""') eq "");
22 ok ('[1,2,3,4]' eq to_json from_json ('[1,2, 3,4]'));
23 ok ('[{},[],[],{}]' eq to_json from_json ('[{},[], [ ] ,{ }]'));
24 ok ('[{"1":[5]}]' eq to_json [{1 => [5]}]);
25 ok ('{"1":2,"3":4}' eq JSON::XS->new->canonical (1)->encode (from_json '{ "1" : 2, "3" : 4 }'));
26 ok ('{"1":2,"3":1.2}' eq JSON::XS->new->canonical (1)->encode (from_json '{ "1" : 2, "3" : 1.2 }'));
27
28 ok ('[true]' eq to_json [JSON::XS::true]);
29 ok ('[false]' eq to_json [JSON::XS::false]);
30 ok ('[true]' eq to_json [\1]);
31 ok ('[false]' eq to_json [\0]);
32 ok ('[null]' eq to_json [undef]);