All the tests now pass with the broken out classes
[dbsrgits/DBM-Deep.git] / t / 39_singletons.t
CommitLineData
867a26a0 1use strict;
c57b19c6 2use Test::More tests => 11;
867a26a0 3use Test::Deep;
4use t::common qw( new_fh );
5
6use_ok( 'DBM::Deep' );
7
c57b19c6 8{
9 my ($fh, $filename) = new_fh();
10 my $db = DBM::Deep->new(
11 file => $filename,
12 locking => 1,
13 autoflush => 1,
14 );
867a26a0 15
c57b19c6 16 $db->{a} = 1;
17 $db->{foo} = { a => 'b' };
18 my $x = $db->{foo};
19 my $y = $db->{foo};
867a26a0 20
888453b9 21 is( $x, $y, "The references are the same" );
22
23 delete $db->{foo};
edd45134 24 is( $x, undef, "After deleting the DB location, external references are also undef (\$x)" );
25 is( $y, undef, "After deleting the DB location, external references are also undef (\$y)" );
26 is( $x + 0, undef, "DBM::Deep::Null can be added to." );
27 is( $y + 0, undef, "DBM::Deep::Null can be added to." );
28 is( $db->{foo}, undef, "The {foo} location is also undef." );
c57b19c6 29
30 # These shenanigans work to get another hashref
31 # into the same data location as $db->{foo} was.
32 $db->{foo} = {};
33 delete $db->{foo};
34 $db->{foo} = {};
35 $db->{bar} = {};
36
edd45134 37 is( $x, undef, "After re-assigning to {foo}, external references to old values are still undef (\$x)" );
38 is( $y, undef, "After re-assigning to {foo}, external references to old values are still undef (\$y)" );
c57b19c6 39}
40
41SKIP: {
42 skip "What do we do with external references and txns?", 2;
43 my ($fh, $filename) = new_fh();
44 my $db = DBM::Deep->new(
45 file => $filename,
46 locking => 1,
47 autoflush => 1,
48 num_txns => 2,
49 );
50
51 $db->{foo} = { a => 'b' };
52 my $x = $db->{foo};
53
54 $db->begin_work;
55
56 $db->{foo} = { c => 'd' };
57 my $y = $db->{foo};
58
59 # XXX What should happen here with $x and $y?
60 is( $x, $y );
61 is( $x->{c}, 'd' );
62
63 $db->rollback;
fb451ba6 64}