Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
5 | use Test::More tests => 13; |
2a81bf9e |
6 | use File::Temp qw( tempfile tempdir ); |
ffed8b01 |
7 | |
8 | use_ok( 'DBM::Deep' ); |
9 | |
2a81bf9e |
10 | my $dir = tempdir( CLEANUP => 1 ); |
11 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
12 | my $db = DBM::Deep->new( $filename ); |
ffed8b01 |
13 | |
14 | ## |
15 | # put/get simple keys |
16 | ## |
17 | $db->{key1} = "value1"; |
18 | $db->{key2} = "value2"; |
19 | |
20 | ## |
21 | # Insert circular reference |
22 | ## |
23 | $db->{circle} = $db; |
24 | |
25 | ## |
26 | # Make sure keys exist in both places |
27 | ## |
28 | is( $db->{key1}, 'value1', "The value is there directly" ); |
29 | is( $db->{circle}{key1}, 'value1', "The value is there in one loop of the circle" ); |
30 | is( $db->{circle}{circle}{key1}, 'value1', "The value is there in two loops of the circle" ); |
31 | is( $db->{circle}{circle}{circle}{key1}, 'value1', "The value is there in three loops of the circle" ); |
32 | |
33 | ## |
34 | # Make sure changes are reflected in both places |
35 | ## |
36 | $db->{key1} = "another value"; |
37 | |
38 | is( $db->{key1}, 'another value', "The value is there directly" ); |
39 | is( $db->{circle}{key1}, 'another value', "The value is there in one loop of the circle" ); |
40 | is( $db->{circle}{circle}{key1}, 'another value', "The value is there in two loops of the circle" ); |
41 | is( $db->{circle}{circle}{circle}{key1}, 'another value', "The value is there in three loops of the circle" ); |
42 | |
43 | $db->{circle}{circle}{circle}{circle}{key1} = "circles"; |
44 | |
45 | is( $db->{key1}, 'circles', "The value is there directly" ); |
46 | is( $db->{circle}{key1}, 'circles', "The value is there in one loop of the circle" ); |
47 | is( $db->{circle}{circle}{key1}, 'circles', "The value is there in two loops of the circle" ); |
48 | is( $db->{circle}{circle}{circle}{key1}, 'circles', "The value is there in three loops of the circle" ); |