Subject: | Data::MessagePack::Unpacker behavior is not the same as Data::MessagePack->unpack |
I found a bug while using Data::MessagePack::Unpacker. It is a bit weird
so I made a test file so you can reproduce it (I hope).
I attached the test file.
When executing this test I obtain:
# Failed test at t/93-mp.t line 44.
# Structures begin differing at:
# $got->[1] = '£ZZZ '
# $expected->[1] = ARRAY(0x8011ec048)
with non threaded perl 5.12.4 on freebsd 64bits and non threaded perl
5.10.1 on linux 32 bits.
Note that if you change the line
["ZZZ",{"" => {}}]
into
["ZZZ"]
the second item can not be unpacked at all...
With PERL_ONLY=1 the test fails but not for the same reason:
# Failed test at t/93-mp.t line 44.
# Structures begin differing at:
# $got->[1][1]{} = Does not exist
# $expected->[1][1]{} = HASH(0x8011f40d8)
Best regards,
Max.
Subject: | 93-mp.t |
# -*- perl -*-
use strict;
use warnings;
use Test::More tests => 3;
my @orig = (
["ZZZ",{"10000050C2400102" => {"1332129147" => ["\x01\x07\x07 \xf7","2.48292"]}}],
["ZZZ",{"" => {}}],
);
use Data::MessagePack;
my $mp = Data::MessagePack->new();
# Just to be sure Data::MessagePack is OK
for (@orig)
{
is_deeply(Data::MessagePack->unpack(Data::MessagePack->pack($_)), $_);
}
# Now test the stream...
my $buf;
for (@orig)
{
$buf .= Data::MessagePack->pack($_);
}
my $up = Data::MessagePack::Unpacker->new;
my @res;
my $offset = $up->execute($buf, 0);
if ($up->is_finished)
{
push(@res, $up->data);
$up->execute($buf, $offset);
if ($up->is_finished)
{
push(@res, $up->data);
is_deeply(\@res, \@orig);
}
else
{
fail('Unpack second item');
}
}
else
{
fail('Unpack first item');
}