ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/t/54_sharing.t
Revision: 1.2
Committed: Fri Sep 8 05:47:10 2023 UTC (9 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.1: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..11\n"; }
2 BEGIN { $^W = 0 } # hate
3 for(1..1e5){
4
5 use CBOR::XS;
6
7 print "ok 1\n";
8
9 sub CBOR::XS::freeze::FREEZE { 77 }
10 sub CBOR::XS::freeze::THAW { \my $dummy }
11
12 $enc = CBOR::XS::encode_cbor_sharing [(bless [], CBOR::XS::freeze::) x 3];
13 print $enc eq (pack "H*", "83d81cd81a825043424f523a3a58533a3a667265657a65184dd81d00d81d00") ? "" : "not ", "ok 2 ", (unpack "H*", $enc), "\n";
14
15 $enc = CBOR::XS->new->allow_sharing->encode ([(bless [], CBOR::XS::freeze::) x 3]);
16 print $enc eq (pack "H*", "83d81cd81a825043424f523a3a58533a3a667265657a65184dd81d00d81d00") ? "" : "not ", "ok 3 ", (unpack "H*", $enc), "\n";
17
18 $dec = decode_cbor $enc;
19 print @$dec == 3 ? "" : "not ", "ok 4 # $dec\n";
20 print ref $dec->[0] ? "" : "not ", "ok 5 # $dec->[0]\n";
21 print $dec->[0] == $dec->[2] ? "" : "not ", "ok 6 # $dec->[0] == $dec->[2]\n";
22
23 $enc = eval { CBOR::XS::decode_cbor pack "H*", "d81c81d81d00" };
24
25 print defined $enc ? "not " : "", "ok 7\n";
26 print $@ =~ /^cyclic / ? "" : "not ", "ok 8\n";
27
28 $dec = CBOR::XS->new->allow_cycles->decode (pack "H*", "d81c81d81d00");
29
30 print ARRAY:: eq ref $dec ? "" : "not ", "ok 9\n";
31 print $dec == $dec->[0] ? "" : "not ", "ok 10\n";
32
33 print "ok 11\n";
34 }
35