Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
5 | use Test::More; |
6 | use Test::Exception; |
7 | |
8 | plan tests => 7; |
9 | |
10 | use_ok( 'DBM::Deep' ); |
11 | |
12 | # How should one test for creation failure with the tie mechanism? |
13 | |
14 | unlink "t/test.db"; |
15 | |
16 | { |
17 | my %hash; |
18 | tie %hash, 'DBM::Deep', "t/test.db"; |
19 | |
20 | $hash{key1} = 'value'; |
21 | is( $hash{key1}, 'value', 'Set and retrieved key1' ); |
22 | } |
23 | |
24 | { |
25 | my %hash; |
26 | tie %hash, 'DBM::Deep', "t/test.db"; |
27 | |
28 | is( $hash{key1}, 'value', 'Set and retrieved key1' ); |
29 | |
30 | is( keys %hash, 1, "There's one key so far" ); |
31 | ok( exists $hash{key1}, "... and it's key1" ); |
32 | } |
33 | |
9d085683 |
34 | throws_ok { |
35 | tie my @array, 'DBM::Deep', { |
36 | file => 't/test.db', |
37 | type => DBM::Deep->TYPE_ARRAY, |
38 | }; |
39 | } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; |
ffed8b01 |
40 | |
9d085683 |
41 | unlink "t/test.db"; |
42 | DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY ); |
43 | |
44 | throws_ok { |
45 | tie my %hash, 'DBM::Deep', { |
46 | file => 't/test.db', |
47 | type => DBM::Deep->TYPE_HASH, |
48 | }; |
49 | } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; |