Added test to demonstrate issue with object created by TIEARRAY
[dbsrgits/DBM-Deep.git] / t / 09_deeparray.t
1 ##
2 # DBM::Deep Test
3 ##
4 $|++;
5 use strict;
6 use Test::More;
7
8 my $max_levels = 1000;
9
10 plan tests => 3;
11
12 use_ok( 'DBM::Deep' );
13 can_ok( 'DBM::Deep', 'new' );
14
15 unlink "t/test.db";
16 my $db = DBM::Deep->new(
17         file => "t/test.db",
18         type => DBM::Deep->TYPE_ARRAY,
19 );
20 print "Check error( $db )\n";
21 if ($db->error()) {
22         die "ERROR: " . $db->error();
23 }
24
25 print "First assignment\n";
26 $db->[0] = [];
27 print "second assignment\n";
28 __END__
29 my $temp_db = $db->[0];
30 print "loop\n";
31 for my $k ( 0 .. $max_levels ) {
32         $temp_db->[$k] = [];
33         $temp_db = $temp_db->[$k];
34 }
35 print "done\n";
36 $temp_db->[0] = "deepvalue";
37 print "undef\n";
38 undef $temp_db;
39
40 undef $db;
41 $db = DBM::Deep->new(
42         file => "t/test.db",
43         type => DBM::Deep->TYPE_ARRAY,
44 );
45
46 my $cur_level = -1;
47 $temp_db = $db->[0];
48 for my $k ( 0 .. $max_levels ) {
49     $cur_level = $k;
50     $temp_db = $temp_db->[$k];
51     eval { $temp_db->isa( 'DBM::Deep' ) } or last;
52 }
53 is( $cur_level, $max_levels, "We read all the way down to level $cur_level" );
54 is( $temp_db->[0], "deepvalue", "And we retrieved the value at the bottom of the ocean" );