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