Renamings
[dbsrgits/DBM-Deep.git] / t / 16_circular.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
5use Test::More tests => 13;
6
7use_ok( 'DBM::Deep' );
8
9unlink "t/test.db";
10my $db = DBM::Deep->new( "t/test.db" );
11if ($db->error()) {
12 die "ERROR: " . $db->error();
13}
14
15##
16# put/get simple keys
17##
18$db->{key1} = "value1";
19$db->{key2} = "value2";
20
21##
22# Insert circular reference
23##
24$db->{circle} = $db;
25
26##
27# Make sure keys exist in both places
28##
29is( $db->{key1}, 'value1', "The value is there directly" );
30is( $db->{circle}{key1}, 'value1', "The value is there in one loop of the circle" );
31is( $db->{circle}{circle}{key1}, 'value1', "The value is there in two loops of the circle" );
32is( $db->{circle}{circle}{circle}{key1}, 'value1', "The value is there in three loops of the circle" );
33
34##
35# Make sure changes are reflected in both places
36##
37$db->{key1} = "another value";
38
39is( $db->{key1}, 'another value', "The value is there directly" );
40is( $db->{circle}{key1}, 'another value', "The value is there in one loop of the circle" );
41is( $db->{circle}{circle}{key1}, 'another value', "The value is there in two loops of the circle" );
42is( $db->{circle}{circle}{circle}{key1}, 'another value', "The value is there in three loops of the circle" );
43
44$db->{circle}{circle}{circle}{circle}{key1} = "circles";
45
46is( $db->{key1}, 'circles', "The value is there directly" );
47is( $db->{circle}{key1}, 'circles', "The value is there in one loop of the circle" );
48is( $db->{circle}{circle}{key1}, 'circles', "The value is there in two loops of the circle" );
49is( $db->{circle}{circle}{circle}{key1}, 'circles', "The value is there in three loops of the circle" );