Skip to content

Commit

Permalink
Add more tests for issue #7
Browse files Browse the repository at this point in the history
Change the tests Steffen added in 0569e4a (derived from
#7) to also test cases where
the sub has a string overload, making sure that subsequent copies of
it stringify to the same thing, and if it returns a reference we'll
stringify that.
  • Loading branch information
avar committed Nov 13, 2012
1 parent 0569e4a commit 314be50
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Perl/Encoder/t/400_evil.t
Expand Up @@ -139,14 +139,27 @@ SCOPE: {

# github Sereal/Sereal issue 7 regression test:
SCOPE: {
my $data = [sub {}];
{
package # hide from PAUSE
My::Lazy::String;
use overload '""' => sub { shift->() };
sub new { bless $_[1] => $_[0] }
}
my $data;
$data->[0] = sub {};
$data->[1] = $data->[0];
$data->[2] = bless sub { "hello there" } => 'My::Lazy::String';
$data->[3] = $data->[2];
$data->[4] = bless sub { \"hello there" } => 'My::Lazy::String';
$data->[5] = $data->[4];

my $encode = encode_sereal($data, {stringify_unknown => 1});
# Before 48d5cdc3dc07fd29ac7be05678a0b614244fec4f, we'd
# die here because $data->[1] is a ref to something that doesn't exist anymore
my $decode = decode_sereal($encode);
is($decode->[0], $decode->[1]);
is($decode->[2], $decode->[3]);
is($decode->[4], $decode->[5]);
}

pass("Alive at end");
Expand Down

0 comments on commit 314be50

Please sign in to comment.