Had to turn off caching, but I've merged everything from SPROUT's fixes
[dbsrgits/DBM-Deep.git] / t / 47_odd_reference_behaviors.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More;
5 use Test::Exception;
6 use Test::Deep;
7
8 use t::common qw( new_dbm );
9
10 use_ok( 'DBM::Deep' );
11
12 # This is bug #34819, reported by EJS
13 {
14     my $dbm_factory = new_dbm();
15     while ( my $dbm_maker = $dbm_factory->() ) {
16         my $db = $dbm_maker->();
17
18         my $bar = bless { foo => 'ope' }, 'Foo';
19
20         eval {
21             $db->{bar} = $bar;
22             $db->{bar} = $bar;
23         }; if ( $@ ) { warn $@ }
24
25         ok(!$@, "repeated object assignment");
26         isa_ok($db->{bar}, 'Foo');
27     }
28 }
29 done_testing;
30 __END__
31 # This is bug #29957, reported by HANENKAMP
32 {
33     my $dbm_factory = new_dbm();
34     while ( my $dbm_maker = $dbm_factory->() ) {
35         my $db = $dbm_maker->();
36
37         $db->{foo} = [];
38
39         for my $value ( 1 .. 3 ) {
40             lives_ok {
41                 my $ref = $db->{foo};
42                 push @$ref, $value;
43                 $db->{foo} = $ref;
44             } "Successfully added value $value";
45         }
46
47         cmp_deeply( [1,2,3], noclass($db->{foo}), "Everything looks ok" );
48     }
49 }
50
51 # This is bug #33863, reported by PJS
52 {
53     my $dbm_factory = new_dbm();
54     while ( my $dbm_maker = $dbm_factory->() ) {
55         my $db = $dbm_maker->();
56
57         $db->{foo} = [ 42 ];
58         my $foo = shift @{ $db->{foo} };
59         cmp_ok( @{ $db->{foo} }, '==', 0, "Shifting a scalar leaves no values" );
60         cmp_ok( $foo, '==', 42, "... And the value is correct." );
61
62         $db->{bar} = [ [] ];
63         my $bar = shift @{ $db->{bar} };
64         cmp_ok( @{ $db->{bar} }, '==', 0, "Shifting an arrayref leaves no values" );
65
66         $db->{baz} = { foo => [ 1 .. 3 ] };
67         $db->{baz2} = [ $db->{baz} ];
68         my $baz2 = shift @{ $db->{baz2} };
69         cmp_ok( @{ $db->{baz2} }, '==', 0, "Shifting an arrayref leaves no values" );
70         ok( exists $db->{baz}{foo} );
71         ok( exists $baz2->{foo} );
72     }
73 }
74
75 done_testing;