ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/t/58_hv.t
Revision: 1.2
Committed: Sun Apr 24 19:31:56 2016 UTC (8 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.1: +9 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.2 BEGIN { $| = 1; print "1..18\n"; }
2 root 1.1
3     # none of the other tests serialise hv's, gross
4     # also checks utf8_strings
5    
6     use CBOR::XS;
7    
8     print "ok 1\n";
9    
10     $enc = encode_cbor {};
11     print $enc ne "\xa0" ? "not " : "", "ok 2\n";
12    
13     $enc = encode_cbor { 5 => 6 };
14     print $enc ne (pack "H*", "a1413506") ? "not " : "", "ok 3\n";
15    
16     $enc = encode_cbor { "" => \my $dummy };
17     print $enc ne (pack "H*", "a140d95652f6") ? "not " : "", "ok 4\n";
18    
19     $enc = encode_cbor { undef() => \my $dummy };
20     print $enc ne (pack "H*", "a140d95652f6") ? "not " : "", "ok 5\n";
21    
22     $enc = encode_cbor { "abc" => "def" };
23     print $enc ne (pack "H*", "a14361626343646566") ? "not " : "", "ok 6\n";
24    
25     $enc = encode_cbor { "abc" => "def", "geh" => "ijk" };
26     print $enc !~ /^\xa2/ ? "not " : "", "ok 7\n";
27     print 17 ne length $enc ? "not " : "", "ok 8\n";
28    
29     $enc = encode_cbor { "\x{7f}" => undef };
30     print $enc ne (pack "H*", "a1417ff6") ? "not " : "", "ok 9\n";
31    
32     $dec = decode_cbor pack "H*", "a1417ff6";
33     print +(keys %$dec)[0] ne "\x{7f}" ? "not " : "", "ok 10\n";
34    
35     $enc = encode_cbor { "\x{100}" => undef };
36     print $enc ne (pack "H*", "a162c480f6") ? "not " : "", "ok 11\n";
37    
38     $dec = decode_cbor pack "H*", "a162c480f6";
39     print +(keys %$dec)[0] ne "\x{100}" ? "not " : "", "ok 12\n";
40    
41     $enc = encode_cbor { "\x{8f}" => undef };
42     print $enc ne (pack "H*", "a1418ff6") ? "not " : "", "ok 13\n";
43    
44     $utf8_strings = CBOR::XS->new->utf8_strings;
45    
46     $enc = $utf8_strings->encode ({ "\x{7f}" => undef });
47     print $enc ne (pack "H*", "a1617ff6") ? "not " : "", "ok 14\n";
48    
49     $enc = $utf8_strings->encode ({ "\x{8f}" => undef });
50     print $enc ne (pack "H*", "a162c28ff6") ? "not " : "", "ok 15\n";
51    
52 root 1.2 $enc = $utf8_strings->encode ({ "\x{8f}gix\x{ff}x" => undef });
53     print $enc ne (pack "H*", "a168c28f676978c3bf78f6") ? "not " : "", "ok 16\n";
54    
55     $dec = decode_cbor pack "H*", "a168c28f676978c3bf78f6";
56     print +(keys %$dec)[0] ne "\x{8f}gix\x{ff}x" ? "not " : "", "ok 17\n";
57    
58     print "ok 18\n";
59