1 | BEGIN { $| = 1; print "1..100\n"; } |
1 | BEGIN { $| = 1; print "1..105\n"; } |
2 | BEGIN { $^W = 0 } # hate |
2 | BEGIN { $^W = 0 } # hate |
3 | |
3 | |
4 | use CBOR::XS; |
4 | use CBOR::XS; |
|
|
5 | |
|
|
6 | use Math::BigInt only => "FastCalc"; # needed for representation stability |
5 | |
7 | |
6 | print "ok 1\n"; |
8 | print "ok 1\n"; |
7 | |
9 | |
8 | my $t = decode_cbor pack "H*", "82c48221196ab3c5822003"; |
10 | my $t = decode_cbor pack "H*", "82c48221196ab3c5822003"; |
9 | |
11 | |
… | |
… | |
12 | |
14 | |
13 | $t = encode_cbor $t; |
15 | $t = encode_cbor $t; |
14 | |
16 | |
15 | print $t eq (pack "H*", "82c48221196ab3c482200f") ? "" : "not ", "ok 4 # ", (unpack "H*", $t), "\n"; |
17 | print $t eq (pack "H*", "82c48221196ab3c482200f") ? "" : "not ", "ok 4 # ", (unpack "H*", $t), "\n"; |
16 | |
18 | |
17 | # Math::BigFloat is loaded by now... |
19 | # Math::BigFloat must be loaded by now... |
18 | |
20 | |
19 | for (5..99) { |
21 | for (5..99) { |
20 | my $n = Math::BigFloat->new ((int rand 1e9) . "." . (int rand 1e9) . "e" . ((int rand 1e8) - 0.5e8)); |
22 | my $n = Math::BigFloat->new ((int rand 1e9) . "." . (int rand 1e9) . "e" . ((int rand 1e8) - 0.5e8)); |
21 | my $m = decode_cbor encode_cbor $n; |
23 | my $m = decode_cbor encode_cbor $n; |
22 | |
24 | |
… | |
… | |
24 | $m = $m->bsstr; |
26 | $m = $m->bsstr; |
25 | |
27 | |
26 | print $n != $m ? "not " : "ok $_ # $n eq $m\n"; |
28 | print $n != $m ? "not " : "ok $_ # $n eq $m\n"; |
27 | } |
29 | } |
28 | |
30 | |
29 | print "ok 100\n"; |
31 | $t = encode_cbor CBOR::XS::tag 264, [Math::BigInt->new ("99999999999999999998"), Math::BigInt->new ("799999999999999999998")]; |
|
|
32 | $t = decode_cbor $t; |
|
|
33 | print "799999999999999999998e+99999999999999999998" eq $t->bsstr ? "" : "not ", "ok 100\n"; |
30 | |
34 | |
|
|
35 | $t = encode_cbor $t; |
|
|
36 | print "d9010882c249056bc75e2d63100000c2492b5e3af16b187ffffe" eq (unpack "H*", $t) ? "" : "not ", "ok 101\n"; |
|
|
37 | |
|
|
38 | $t = encode_cbor CBOR::XS::tag 30, [4, 2]; |
|
|
39 | $t = decode_cbor $t; |
|
|
40 | print $t eq 2 ? "" : "not ", "ok 102 # $t\n"; |
|
|
41 | |
|
|
42 | $t = encode_cbor $t; |
|
|
43 | print "02" eq (unpack "H*", $t) ? "" : "not ", "ok 103\n"; |
|
|
44 | |
|
|
45 | $t = encode_cbor decode_cbor encode_cbor CBOR::XS::tag 30, [Math::BigInt->new (5), 2]; |
|
|
46 | print "d81e820502" eq (unpack "H*", $t) ? "" : "not ", "ok 104\n"; |
|
|
47 | |
|
|
48 | print "ok 105\n"; |
|
|
49 | |