Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
535203b1 |
5 | use Test::More; |
6 | |
7 | plan skip_all => "You must set \$ENV{LONG_TESTS} to run the long tests" |
8 | unless $ENV{LONG_TESTS}; |
9 | |
10 | plan tests => 5; |
fde3db1a |
11 | use t::common qw( new_fh ); |
ffed8b01 |
12 | |
13ff93d5 |
13 | diag "This test can take up to a minute to run. Please be patient."; |
14 | |
ffed8b01 |
15 | use_ok( 'DBM::Deep' ); |
16 | |
fde3db1a |
17 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
18 | |
2a81bf9e |
19 | my $max_levels = 1000; |
ffed8b01 |
20 | |
2a81bf9e |
21 | { |
22 | my $db = DBM::Deep->new( |
23 | file => $filename, |
0856d3d8 |
24 | fh => $fh, |
2a81bf9e |
25 | type => DBM::Deep->TYPE_HASH, |
26 | ); |
27 | |
28 | ## |
29 | # basic deep hash |
30 | ## |
31 | $db->{company} = {}; |
32 | $db->{company}->{name} = "My Co."; |
33 | $db->{company}->{employees} = {}; |
34 | $db->{company}->{employees}->{"Henry Higgins"} = {}; |
35 | $db->{company}->{employees}->{"Henry Higgins"}->{salary} = 90000; |
36 | |
37 | is( $db->{company}->{name}, "My Co.", "Set and retrieved a second-level value" ); |
38 | is( $db->{company}->{employees}->{"Henry Higgins"}->{salary}, 90000, "Set and retrieved a fourth-level value" ); |
39 | |
40 | ## |
41 | # super deep hash |
42 | ## |
43 | $db->{base_level} = {}; |
44 | my $temp_db = $db->{base_level}; |
45 | |
46 | for my $k ( 0 .. $max_levels ) { |
47 | $temp_db->{"level$k"} = {}; |
48 | $temp_db = $temp_db->{"level$k"}; |
49 | } |
50 | $temp_db->{deepkey} = "deepvalue"; |
ffed8b01 |
51 | } |
2a81bf9e |
52 | |
53 | { |
0856d3d8 |
54 | open $fh, '+<', $filename; |
2a81bf9e |
55 | my $db = DBM::Deep->new( |
56 | file => $filename, |
0856d3d8 |
57 | fh => $fh, |
2a81bf9e |
58 | type => DBM::Deep->TYPE_HASH, |
59 | ); |
60 | |
61 | my $cur_level = -1; |
62 | my $temp_db = $db->{base_level}; |
63 | for my $k ( 0 .. $max_levels ) { |
64 | $cur_level = $k; |
65 | $temp_db = $temp_db->{"level$k"}; |
66 | eval { $temp_db->isa( 'DBM::Deep' ) } or last; |
67 | } |
68 | is( $cur_level, $max_levels, "We read all the way down to level $cur_level" ); |
69 | is( $temp_db->{deepkey}, "deepvalue", "And we retrieved the value at the bottom of the ocean" ); |
ffed8b01 |
70 | } |