File: 03_stream_unpack.t

package info (click to toggle)
libdata-messagepack-perl 1.02-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,060 kB
  • sloc: ansic: 5,697; perl: 1,123; makefile: 10
file content (43 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use t::Util;
use Test::More;
use Data::MessagePack;

no warnings 'uninitialized'; # i need this. i need this.

my $up = Data::MessagePack::Unpacker->new;
sub unpackit {
    my $v = $_[0];
    $v =~ s/ //g;
    $v = pack 'H*', $v;
    $up->reset;
    my $ret = $up->execute($v, 0);
    if ($ret != length($v)) {
        fail "extra bytes";
    }
    return $up->data;
}

sub pis ($$) {
    is_deeply unpackit($_[0]), $_[1], 'dump ' . $_[0];
}

my @dat = do 't/data.pl';

plan tests => 1*(scalar(@dat)/2) + 3;

isa_ok $up, 'Data::MessagePack::Unpacker';
for (my $i=0; $i<scalar(@dat); ) {
    pis $dat[$i++], $dat[$i++];
}

# devided.
{
    my $up = Data::MessagePack::Unpacker->new();
    $up->execute("\x95", 0); # array marker
    for (1..5) {
        $up->execute("\xc0", 0); # nil
    }
    ok $up->is_finished, 'finished';
    is_deeply $up->data, [undef, undef, undef, undef, undef], 'array, is_deeply';
}