Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
5 | use Test::More; |
6 | |
7 | my $max_levels = 1000; |
8 | |
9 | plan tests => $max_levels + 5; |
10 | |
11 | use_ok( 'DBM::Deep' ); |
12 | |
13 | unlink "t/test.db"; |
14 | my $db = DBM::Deep->new( |
15 | file => "t/test.db" |
16 | ); |
17 | if ($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 | |
30 | is( $db->{company}->{name}, "My Co.", "Set and retrieved a second-level value" ); |
31 | is( $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} = {}; |
37 | my $temp_db = $db->{base_level}; |
38 | |
39 | for my $k ( 0 .. $max_levels ) { |
40 | $temp_db->{"level$k"} = {}; |
41 | $temp_db = $temp_db->{"level$k"}; |
42 | } |
43 | $temp_db->{deepkey} = "deepvalue"; |
44 | undef $temp_db; |
45 | |
46 | undef $db; |
47 | $db = DBM::Deep->new( |
48 | file => "t/test.db" |
49 | ); |
50 | |
51 | $temp_db = $db->{base_level}; |
52 | for my $k ( 0 .. $max_levels ) { |
53 | $temp_db = $temp_db->{"level$k"}; |
54 | isa_ok( $temp_db, 'DBM::Deep' ) || die "Whoops!"; |
55 | } |
56 | is( $temp_db->{deepkey}, "deepvalue", "And we retrieved the value at the bottom of the ocean" ); |