Renamings
[dbsrgits/DBM-Deep.git] / t / 08_deephash.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
5use Test::More;
6
7my $max_levels = 1000;
8
9plan tests => $max_levels + 5;
10
11use_ok( 'DBM::Deep' );
12
13unlink "t/test.db";
14my $db = DBM::Deep->new(
15 file => "t/test.db"
16);
17if ($db->error()) {
18 die "ERROR: " . $db->error();
19}
20
21##
22# basic deep hash
23##
24$db->{company} = {};
25$db->{company}->{name} = "My Co.";
26$db->{company}->{employees} = {};
27$db->{company}->{employees}->{"Henry Higgins"} = {};
28$db->{company}->{employees}->{"Henry Higgins"}->{salary} = 90000;
29
30is( $db->{company}->{name}, "My Co.", "Set and retrieved a second-level value" );
31is( $db->{company}->{employees}->{"Henry Higgins"}->{salary}, 90000, "Set and retrieved a fourth-level value" );
32
33##
34# super deep hash
35##
36$db->{base_level} = {};
37my $temp_db = $db->{base_level};
38
39for my $k ( 0 .. $max_levels ) {
40 $temp_db->{"level$k"} = {};
41 $temp_db = $temp_db->{"level$k"};
42}
43$temp_db->{deepkey} = "deepvalue";
44undef $temp_db;
45
46undef $db;
47$db = DBM::Deep->new(
48 file => "t/test.db"
49);
50
51$temp_db = $db->{base_level};
52for my $k ( 0 .. $max_levels ) {
53 $temp_db = $temp_db->{"level$k"};
54 isa_ok( $temp_db, 'DBM::Deep' ) || die "Whoops!";
55}
56is( $temp_db->{deepkey}, "deepvalue", "And we retrieved the value at the bottom of the ocean" );