1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
use strict;
use warnings FATAL => 'all';
use Test::More;
use t::common qw( new_dbm new_fh );
use_ok( 'DBM::Deep' );
my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
my $db = $dbm_maker->();
$db->import({
hash1 => {
subkey1 => "subvalue1",
subkey2 => "subvalue2",
},
hash2 => {
subkey3 => 'subvalue3',
},
});
is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
$db->{copy} = $db->{hash1};
is( $db->{copy}{subkey1}, 'subvalue1', "Value copied correctly" );
is( $db->{copy}{subkey2}, 'subvalue2', "Value copied correctly" );
$db->{copy}{subkey1} = "another value";
is( $db->{copy}{subkey1}, 'another value', "New value is set correctly" );
is( $db->{hash1}{subkey1}, 'another value', "Old value is set to the new one" );
is( scalar(keys %{$db->{hash1}}), 2, "Start with 2 keys in the original" );
is( scalar(keys %{$db->{copy}}), 2, "Start with 2 keys in the copy" );
delete $db->{copy}{subkey2};
is( scalar(keys %{$db->{copy}}), 1, "Now only have 1 key in the copy" );
is( scalar(keys %{$db->{hash1}}), 1, "... and only 1 key in the original" );
$db->{copy} = $db->{hash2};
is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" );
}
{
my $max_keys = 1000;
my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
{
my $db = $dbm_maker->();
$db->{foo} = [ 1 .. 3 ];
for ( 0 .. $max_keys ) {
$db->{'foo' . $_} = $db->{foo};
}
}
{
my $db = $dbm_maker->();
my $base_offset = $db->{foo}->_base_offset;
my $count = -1;
for ( 0 .. $max_keys ) {
$count = $_;
unless ( $base_offset == $db->{'foo'.$_}->_base_offset ) {
last;
}
}
is( $count, $max_keys, "We read $count keys" );
}
}
}
done_testing;
|