test and fix added for defect #34819
[dbsrgits/DBM-Deep.git] / t / 47_odd_reference_behaviors.t
1 use 5.006;
2
3 use strict;
4 use warnings FATAL => 'all';
5
6 use Scalar::Util qw( reftype );
7 use Test::More tests => 12;
8
9 use t::common qw( new_fh );
10
11 use_ok( 'DBM::Deep' );
12
13 # This is bug #34819, reported by EJS
14 {
15     my ($fh, $filename) = new_fh();
16     my $db = DBM::Deep->new(
17         file => $filename,
18         fh => $fh,
19     );
20
21     my $bar = bless { foo => 'bar' }, 'Foo';
22
23     eval {
24         $db->{bar} = $bar;
25         $db->{bar} = $bar;
26     };
27
28     ok(!$@, "repeated object assignment");
29     isa_ok($db->{bar}, 'Foo');
30 }
31
32 # This is bug #29957, reported by HANENKAMP
33 TODO: {
34     todo_skip "This crashes the code", 4;
35     my ($fh, $filename) = new_fh();
36     my $db = DBM::Deep->new(
37         file => $filename,
38         fh => $fh,
39     );
40
41     $db->{foo} = [];
42
43     for my $value ( 1 .. 3 ) {
44         my $ref = $db->{foo};
45         push @$ref, $value;
46         $db->{foo} = $ref;
47         ok( 1, "T $value" );
48     }
49 }
50
51 # This is bug #33863, reported by PJS
52 {
53     my ($fh, $filename) = new_fh();
54     my $db = DBM::Deep->new(
55         file => $filename,
56         fh => $fh,
57     );
58
59     $db->{foo} = [ 42 ];
60     my $foo = shift @{ $db->{foo} };
61     cmp_ok( @{ $db->{foo} }, '==', 0, "Shifting a scalar leaves no values" );
62     cmp_ok( $foo, '==', 42, "... And the value is correct." );
63
64 #    $db->{bar} = [ [] ];
65 #    my $bar = shift @{ $db->{bar} };
66 #    cmp_ok( @{ $db->{bar} }, '==', 0, "Shifting an arrayref leaves no values" );
67 #    use Data::Dumper; warn Dumper $bar;
68
69     $db->{baz} = { foo => [ 1 .. 3 ] };
70     $db->{baz2} = [ $db->{baz} ];
71     my $baz2 = shift @{ $db->{baz2} };
72     cmp_ok( @{ $db->{baz2} }, '==', 0, "Shifting an arrayref leaves no values" );
73     ok( exists $db->{baz}{foo} );
74     ok( exists $baz2->{foo} );
75 }
76
77 __END__