5 use Test::More tests => 13;
7 use t::common qw( new_fh );
12 my ($fh, $filename) = new_fh();
13 my $db = DBM::Deep->new({
21 my $size = -s $filename;
23 cmp_ok( $size, '==', -s $filename, "A second overwrite doesn't change size" );
27 cmp_ok( $size, '==', -s $filename, "Deleted space isn't released" );
30 cmp_ok( $size, '==', -s $filename, "Added a new key after a delete reuses space" );
38 cmp_ok( $size, '==', -s $filename, "delete and rewrite reuses space" );
45 cmp_ok( $size, '==', -s $filename, "delete and rewrite reuses space" );
47 my $x = { foo => 'bar' };
50 delete $db->{floober};
52 ok( !exists $x->{foo}, "Deleting floober makes \$x empty (exists)" );
53 is( $x->{foo}, undef, "Deleting floober makes \$x empty (read)" );
54 is( delete $x->{foo}, undef, "Deleting floober makes \$x empty (delete)" );
56 eval { $x->{foo} = 'bar'; };
57 like( $@, qr/Cannot write to a deleted spot in DBM::Deep/, "Exception thrown when writing" );
59 cmp_ok( scalar( keys %$x ), '==', 0, "Keys returns nothing after deletion" );
63 my ($fh, $filename) = new_fh();
64 my $db = DBM::Deep->new({
69 $db->{ $_ } = undef for 1 .. 4;
70 delete $db->{ $_ } for 1 .. 4;
71 cmp_ok( keys %{ $db }, '==', 0, "We added and removed 4 keys" );
73 # So far, we've written 4 keys. Let's write 13 more keys. This should -not-
74 # trigger a reindex. This requires knowing how much space is taken. Good thing
75 # we wrote this dreck ...
76 my $size = -s $filename;
78 my $expected = $size + 9 * ( 256 + 256 );
80 $db->{ $_ } = undef for 5 .. 17;
82 cmp_ok( $expected, '==', -s $filename, "No reindexing after deletion" );