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