Cleaned up open() a bit
[dbsrgits/DBM-Deep.git] / t / 16_circular.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
5use Test::More tests => 13;
2a81bf9e 6use File::Temp qw( tempfile tempdir );
ffed8b01 7
8use_ok( 'DBM::Deep' );
9
2a81bf9e 10my $dir = tempdir( CLEANUP => 1 );
11my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
12my $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##
28is( $db->{key1}, 'value1', "The value is there directly" );
29is( $db->{circle}{key1}, 'value1', "The value is there in one loop of the circle" );
30is( $db->{circle}{circle}{key1}, 'value1', "The value is there in two loops of the circle" );
31is( $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
38is( $db->{key1}, 'another value', "The value is there directly" );
39is( $db->{circle}{key1}, 'another value', "The value is there in one loop of the circle" );
40is( $db->{circle}{circle}{key1}, 'another value', "The value is there in two loops of the circle" );
41is( $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
45is( $db->{key1}, 'circles', "The value is there directly" );
46is( $db->{circle}{key1}, 'circles', "The value is there in one loop of the circle" );
47is( $db->{circle}{circle}{key1}, 'circles', "The value is there in two loops of the circle" );
48is( $db->{circle}{circle}{circle}{key1}, 'circles', "The value is there in three loops of the circle" );