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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
use strict;
use warnings FATAL => 'all';
use Test::More;
use Test::Exception;
use Test::Deep;
use t::common qw( new_dbm );
use_ok( 'DBM::Deep' );
# This is bug #34819, reported by EJS
{
my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
my $db = $dbm_maker->();
my $bar = bless { foo => 'ope' }, 'Foo';
eval {
$db->{bar} = $bar;
$db->{bar} = $bar;
}; if ( $@ ) { warn $@ }
ok(!$@, "repeated object assignment");
isa_ok($db->{bar}, 'Foo');
}
}
done_testing;
__END__
# This is bug #29957, reported by HANENKAMP
{
my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
my $db = $dbm_maker->();
$db->{foo} = [];
for my $value ( 1 .. 3 ) {
lives_ok {
my $ref = $db->{foo};
push @$ref, $value;
$db->{foo} = $ref;
} "Successfully added value $value";
}
cmp_deeply( [1,2,3], noclass($db->{foo}), "Everything looks ok" );
}
}
# This is bug #33863, reported by PJS
{
my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
my $db = $dbm_maker->();
$db->{foo} = [ 42 ];
my $foo = shift @{ $db->{foo} };
cmp_ok( @{ $db->{foo} }, '==', 0, "Shifting a scalar leaves no values" );
cmp_ok( $foo, '==', 42, "... And the value is correct." );
$db->{bar} = [ [] ];
my $bar = shift @{ $db->{bar} };
cmp_ok( @{ $db->{bar} }, '==', 0, "Shifting an arrayref leaves no values" );
$db->{baz} = { foo => [ 1 .. 3 ] };
$db->{baz2} = [ $db->{baz} ];
my $baz2 = shift @{ $db->{baz2} };
cmp_ok( @{ $db->{baz2} }, '==', 0, "Shifting an arrayref leaves no values" );
ok( exists $db->{baz}{foo} );
ok( exists $baz2->{foo} );
}
}
done_testing;
|