Fixed how classname is stored
[dbsrgits/DBM-Deep.git] / t / 45_references.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More;
5 use Test::Exception;
6 use t::common qw( new_dbm );
7
8 use_ok( 'DBM::Deep' );
9
10 my $dbm_factory = new_dbm(
11     locking => 1,
12     autoflush => 1,
13     num_txns  => 16,
14 );
15 while ( my $dbm_maker = $dbm_factory->() ) {
16     my $db1 = $dbm_maker->();
17     my $db2 = $dbm_maker->();
18
19     $db1->{foo} = 5;
20     $db1->{bar} = $db1->{foo};
21
22     is( $db1->{foo}, 5, "Foo is still 5" );
23     is( $db1->{bar}, 5, "Bar is now 5" );
24
25     $db1->{foo} = 6;
26
27     is( $db1->{foo}, 6, "Foo is now 6" );
28     is( $db1->{bar}, 5, "Bar is still 5" );
29
30     $db1->{foo} = [ 1 .. 3 ];
31     $db1->{bar} = $db1->{foo};
32
33     is( $db1->{foo}[1], 2, "Foo[1] is still 2" );
34     is( $db1->{bar}[1], 2, "Bar[1] is now 2" );
35
36     $db1->{foo}[3] = 42;
37
38     is( $db1->{foo}[3], 42, "Foo[3] is now 42" );
39     is( $db1->{bar}[3], 42, "Bar[3] is also 42" );
40
41     delete $db1->{foo};
42     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
43
44     $db1->{foo} = $db1->{bar};
45     $db2->begin_work;
46
47         delete $db2->{bar};
48         delete $db2->{foo};
49
50         is( $db2->{bar}, undef, "It's deleted in the transaction" );
51         is( $db1->{bar}[3], 42, "... but not in the main" );
52
53     $db2->rollback;
54
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" );
59
60     delete $db1->{foo};
61
62     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
63 }
64
65 done_testing;
66
67 __END__
68 warn "-2\n";
69 $db2->begin_work;
70
71 warn "-1\n";
72   delete $db2->{bar};
73
74 warn "0\n";
75 $db2->commit;
76
77 warn "1\n";
78 ok( !exists $db1->{bar}, "After commit, bar is gone" );
79 warn "2\n";