New testing feature that allows specification of the workdir for the tests
[dbsrgits/DBM-Deep.git] / t / 09_deeparray.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 3;
6 use t::common qw( new_fh );
7
8 use_ok( 'DBM::Deep' );
9
10 my ($fh, $filename) = new_fh();
11
12 my $max_levels = 1000;
13
14 {
15     my $db = DBM::Deep->new(
16         file => $filename,
17         type => DBM::Deep->TYPE_ARRAY,
18     );
19
20     $db->[0] = [];
21     my $temp_db = $db->[0];
22     for my $k ( 0 .. $max_levels ) {
23         $temp_db->[$k] = [];
24         $temp_db = $temp_db->[$k];
25     }
26     $temp_db->[0] = "deepvalue";
27 }
28
29 {
30     my $db = DBM::Deep->new(
31         file => $filename,
32         type => DBM::Deep->TYPE_ARRAY,
33     );
34
35     my $cur_level = -1;
36     my $temp_db = $db->[0];
37     for my $k ( 0 .. $max_levels ) {
38         $cur_level = $k;
39         $temp_db = $temp_db->[$k];
40         eval { $temp_db->isa( 'DBM::Deep' ) } or last;
41     }
42     is( $cur_level, $max_levels, "We read all the way down to level $cur_level" );
43     is( $temp_db->[0], "deepvalue", "And we retrieved the value at the bottom of the ocean" );
44 }