Activated more tests marked as skip-all until internal references are supported
[dbsrgits/DBM-Deep.git] / t / 22_internal_copy.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
c8a41eb0 5use Test::More skip_all => "Internal references are not supported right now";
6#use Test::More tests => 13;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
fde3db1a 11my ($fh, $filename) = new_fh();
98ac82af 12my $db = DBM::Deep->new( $filename );
ffed8b01 13
14##
15# Create structure in $db
16##
17$db->import(
18 hash1 => {
19 subkey1 => "subvalue1",
20 subkey2 => "subvalue2",
21 },
22 hash2 => {
23 subkey3 => 'subvalue3',
24 },
25);
26
27is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
28is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
29
30$db->{copy} = $db->{hash1};
31
32is( $db->{copy}{subkey1}, 'subvalue1', "Value copied correctly" );
33is( $db->{copy}{subkey2}, 'subvalue2', "Value copied correctly" );
34
35$db->{copy}{subkey1} = "another value";
36is( $db->{copy}{subkey1}, 'another value', "New value is set correctly" );
37is( $db->{hash1}{subkey1}, 'another value', "Old value is set to the new one" );
38
39is( scalar(keys %{$db->{hash1}}), 2, "Start with 2 keys in the original" );
40is( scalar(keys %{$db->{copy}}), 2, "Start with 2 keys in the copy" );
41
42delete $db->{copy}{subkey2};
43
44is( scalar(keys %{$db->{copy}}), 1, "Now only have 1 key in the copy" );
45is( scalar(keys %{$db->{hash1}}), 1, "... and only 1 key in the original" );
46
47$db->{copy} = $db->{hash2};
48is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" );
81e8596e 49my $max_keys = 1000;
50
fde3db1a 51my ($fh2, $filename2) = new_fh();
81e8596e 52{
98ac82af 53 my $db = DBM::Deep->new( $filename2 );
81e8596e 54
55 $db->{foo} = [ 1 .. 3 ];
56 for ( 0 .. $max_keys ) {
57 $db->{'foo' . $_} = $db->{foo};
58 }
59}
60
61{
98ac82af 62 my $db = DBM::Deep->new( $filename2 );
81e8596e 63
64 my $base_offset = $db->{foo}->_base_offset;
65 my $count = -1;
66 for ( 0 .. $max_keys ) {
67 $count = $_;
68 unless ( $base_offset == $db->{'foo'.$_}->_base_offset ) {
69 last;
70 }
71 }
72 is( $count, $max_keys, "We read $count keys" );
73}