ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/52_object.t
Revision: 1.1
Committed: Mon Oct 28 23:19:54 2013 UTC (10 years, 8 months ago) by root
Content type: application/x-troff
Branch: MAIN
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;
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 $json = JSON::XS->new->allow_tags->allow_nonref;
26
27 sub JSON::XS::freeze::FREEZE {
28 print @_ == 2 ? "" : "not ", "ok 8\n";
29 print $_[1] eq "JSON" ? "" : "not ", "ok 9\n";
30 print JSON::XS::freeze:: eq ref $_[0] ? "" : "not ", "ok 10\n";
31 print $_[0]{k} == 1 ? "" : "not ", "ok 11\n";
32 (3, 1, 2)
33 }
34
35 sub JSON::XS::freeze::THAW {
36 print @_ == 5 ? "" : "not ", "ok 13\n";
37 print JSON::XS::freeze:: eq $_[0] ? "" : "not ", "ok 14\n";
38 print $_[1] eq "JSON" ? "" : "not ", "ok 15\n";
39 print $_[2] == 3 ? "" : "not ", "ok 16\n";
40 print $_[3] == 1 ? "" : "not ", "ok 17\n";
41 print $_[4] == 2 ? "" : "not ", "ok 18\n";
42 777
43 }
44
45 $obj = bless { k => 1 }, JSON::XS::freeze::;
46 $enc = $json->encode ($obj);
47 print $enc eq '("JSON::XS::freeze")[3,1,2]' ? "" : "not ", "ok 12 # $enc\n";
48
49 $dec = $json->decode ($enc);
50 print $dec eq 777 ? "" : "not ", "ok 19\n";
51
52 print "ok 20\n";
53