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 | |
34 | TODO: { |
35 | local $TODO = "Sig doesn't match, but it's legal??"; |
36 | my @array; |
37 | throws_ok { |
38 | tie @array, 'DBM::Deep', { |
39 | file => 't/test.db', |
40 | type => DBM::Deep->TYPE_ARRAY, |
41 | }; |
42 | } qr/DBM::Deep: Cannot open a hash-based file with an array/, "\$SIG_TYPE doesn't match file's type"; |
43 | |
44 | unlink "t/test.db"; |
45 | DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY ); |
46 | |
47 | my %hash; |
48 | throws_ok { |
49 | tie %hash, 'DBM::Deep', { |
50 | file => 't/test.db', |
51 | type => DBM::Deep->TYPE_HASH, |
52 | }; |
53 | } qr/DBM::Deep: Cannot open a array-based file with a hash/, "\$SIG_TYPE doesn't match file's type"; |
54 | } |