ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/52_object.t
Revision: 1.2
Committed: Mon Oct 28 23:23:11 2013 UTC (10 years, 8 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_0
Changes since 1.1: +1 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..20\n"; }
2
3 use JSON::XS;
4
5 $json = JSON::XS->new->convert_blessed->allow_tags->allow_nonref;
6
7 print "ok 1\n";
8
9 sub JSON::XS::tojson::TO_JSON {
10 print @_ == 1 ? "" : "not ", "ok 3\n";
11 print JSON::XS::tojson:: eq ref $_[0] ? "" : "not ", "ok 4\n";
12 print $_[0]{k} == 1 ? "" : "not ", "ok 5\n";
13 7
14 }
15
16 $obj = bless { k => 1 }, JSON::XS::tojson::;
17
18 print "ok 2\n";
19
20 $enc = $json->encode ($obj);
21 print $enc eq 7 ? "" : "not ", "ok 6 # $enc\n";
22
23 print "ok 7\n";
24
25 sub JSON::XS::freeze::FREEZE {
26 print @_ == 2 ? "" : "not ", "ok 8\n";
27 print $_[1] eq "JSON" ? "" : "not ", "ok 9\n";
28 print JSON::XS::freeze:: eq ref $_[0] ? "" : "not ", "ok 10\n";
29 print $_[0]{k} == 1 ? "" : "not ", "ok 11\n";
30 (3, 1, 2)
31 }
32
33 sub JSON::XS::freeze::THAW {
34 print @_ == 5 ? "" : "not ", "ok 13\n";
35 print JSON::XS::freeze:: eq $_[0] ? "" : "not ", "ok 14\n";
36 print $_[1] eq "JSON" ? "" : "not ", "ok 15\n";
37 print $_[2] == 3 ? "" : "not ", "ok 16\n";
38 print $_[3] == 1 ? "" : "not ", "ok 17\n";
39 print $_[4] == 2 ? "" : "not ", "ok 18\n";
40 777
41 }
42
43 $obj = bless { k => 1 }, JSON::XS::freeze::;
44 $enc = $json->encode ($obj);
45 print $enc eq '("JSON::XS::freeze")[3,1,2]' ? "" : "not ", "ok 12 # $enc\n";
46
47 $dec = $json->decode ($enc);
48 print $dec eq 777 ? "" : "not ", "ok 19\n";
49
50 print "ok 20\n";
51