Add tests

This commit is contained in:
Fuji, Goro 2010-10-12 22:58:53 +09:00
parent c10eb2c17b
commit 2b65f81e23

View File

@ -1,15 +1,16 @@
use strict; use strict;
use warnings; use warnings;
use Data::MessagePack; use Data::MessagePack;
use Test::More tests => 9; use Test::More tests => 61;
use t::Util; use t::Util;
my $input = [ my $input = [
false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1, false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,
127,127,255,65535,4294967295,-32,-32,-128,-32768, 127,127,255,65535,4294967295,-32,-32,-128,-32768,
-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","", -2147483648,0.0,-0.0, 3.14,-3.14,"a","a","a","","","",
[0],[0],[0],[],[],[],{},{},{}, [0],[0],[0],[],[],[],{},{},{},
{"a" => 97},{"a" => 97},{"a" => 97},[[]],[["a"]] {"a" => 97},{"abc" => 97},{"xyz" => 97},[[]], [["foo"], ["bar"]],
[["foo", true, false, null, 42]],
]; ];
my $packed = Data::MessagePack->pack($input); my $packed = Data::MessagePack->pack($input);
@ -40,4 +41,21 @@ is_deeply(Data::MessagePack->unpack($packed), $input);
} }
} }
{
my $s = '';
foreach my $datum(reverse @{$input}) {
$s .= Data::MessagePack->pack($datum);
}
my $up = Data::MessagePack::Unpacker->new();
my $offset = 0;
for my $datum(reverse @{$input}) {
note "offset: $offset/".length($s);
$offset = $up->execute($s, $offset);
is_deeply $up->data, $datum;
$up->reset();
}
}