5 use Test::More tests => 19;
6 use File::Temp qw( tempfile tempdir );
10 my $dir = tempdir( CLEANUP => 1 );
11 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
12 my $db = DBM::Deep->new( $filename );
17 $db->{key1} = "value1";
18 $db->{key2} = "value2";
20 my @keys_1 = sort keys %$db;
22 $db->{key3} = $db->{key1};
24 my @keys_2 = sort keys %$db;
25 is( @keys_2 + 0, @keys_1 + 1, "Correct number of keys" );
29 "Keys still match after circular reference is added",
33 $db->{key5} = $db->{key4};
35 my @keys_3 = sort keys %$db;
38 local $TODO = "Need to fix how internal references are stored";
39 is( @keys_3 + 0, @keys_2 + 2, "Correct number of keys" );
41 [ @keys_2, 'key4', 'key5' ],
43 "Keys still match after circular reference is added (@keys_3)",
47 # Insert circular reference
51 my @keys_4 = sort keys %$db;
54 is( @keys_4 + 0, @keys_3 + 1, "Correct number of keys" );
56 [ '[base]', @keys_3 ],
58 "Keys still match after circular reference is added",
63 # Make sure keys exist in both places
65 is( $db->{key1}, 'value1', "The value is there directly" );
66 is( $db->{circle}{key1}, 'value1', "The value is there in one loop of the circle" );
67 is( $db->{circle}{circle}{key1}, 'value1', "The value is there in two loops of the circle" );
68 is( $db->{circle}{circle}{circle}{key1}, 'value1', "The value is there in three loops of the circle" );
71 # Make sure changes are reflected in both places
73 $db->{key1} = "another value";
75 is( $db->{key1}, 'another value', "The value is there directly" );
76 is( $db->{circle}{key1}, 'another value', "The value is there in one loop of the circle" );
77 is( $db->{circle}{circle}{key1}, 'another value', "The value is there in two loops of the circle" );
78 is( $db->{circle}{circle}{circle}{key1}, 'another value', "The value is there in three loops of the circle" );
80 $db->{circle}{circle}{circle}{circle}{key1} = "circles";
82 is( $db->{key1}, 'circles', "The value is there directly" );
83 is( $db->{circle}{key1}, 'circles', "The value is there in one loop of the circle" );
84 is( $db->{circle}{circle}{key1}, 'circles', "The value is there in two loops of the circle" );
85 is( $db->{circle}{circle}{circle}{key1}, 'circles', "The value is there in three loops of the circle" );