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