Fixed problem with second-level values being overwritten when accessed.
[dbsrgits/DBM-Deep.git] / t / 45_references.t
CommitLineData
1cff45d7 1use strict;
0e3e3555 2use warnings FATAL => 'all';
3
4use Test::More;
1cff45d7 5use Test::Exception;
0e3e3555 6use t::common qw( new_dbm );
1cff45d7 7
8use_ok( 'DBM::Deep' );
9
0e3e3555 10my $dbm_factory = new_dbm(
888453b9 11 locking => 1,
12 autoflush => 1,
13 num_txns => 16,
14);
0e3e3555 15while ( my $dbm_maker = $dbm_factory->() ) {
16 my $db1 = $dbm_maker->();
17 my $db2 = $dbm_maker->();
888453b9 18
0e3e3555 19 $db1->{foo} = 5;
20 $db1->{bar} = $db1->{foo};
45f047f8 21
0e3e3555 22 is( $db1->{foo}, 5, "Foo is still 5" );
23 is( $db1->{bar}, 5, "Bar is now 5" );
1cff45d7 24
0e3e3555 25 $db1->{foo} = 6;
1cff45d7 26
0e3e3555 27 is( $db1->{foo}, 6, "Foo is now 6" );
28 is( $db1->{bar}, 5, "Bar is still 5" );
1cff45d7 29
0e3e3555 30 $db1->{foo} = [ 1 .. 3 ];
31 $db1->{bar} = $db1->{foo};
1cff45d7 32
0e3e3555 33 is( $db1->{foo}[1], 2, "Foo[1] is still 2" );
34 is( $db1->{bar}[1], 2, "Bar[1] is now 2" );
1cff45d7 35
0e3e3555 36 $db1->{foo}[3] = 42;
1cff45d7 37
0e3e3555 38 is( $db1->{foo}[3], 42, "Foo[3] is now 42" );
39 is( $db1->{bar}[3], 42, "Bar[3] is also 42" );
1cff45d7 40
0e3e3555 41 delete $db1->{foo};
42 is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
1cff45d7 43
0e3e3555 44 $db1->{foo} = $db1->{bar};
45 $db2->begin_work;
888453b9 46
0e3e3555 47 delete $db2->{bar};
48 delete $db2->{foo};
888453b9 49
0e3e3555 50 is( $db2->{bar}, undef, "It's deleted in the transaction" );
51 is( $db1->{bar}[3], 42, "... but not in the main" );
888453b9 52
0e3e3555 53 $db2->rollback;
888453b9 54
0e3e3555 55 # Why hasn't this failed!? Is it because stuff isn't getting deleted as
56 # expected? I need a test that walks the sectors
57 is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
58 is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
888453b9 59
0e3e3555 60 delete $db1->{foo};
888453b9 61
0e3e3555 62 is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
63}
888453b9 64
0e3e3555 65done_testing;
888453b9 66
67__END__
68warn "-2\n";
69$db2->begin_work;
70
71warn "-1\n";
72 delete $db2->{bar};
73
74warn "0\n";
75$db2->commit;
76
77warn "1\n";
0e3e3555 78ok( !exists $db1->{bar}, "After commit, bar is gone" );
888453b9 79warn "2\n";