Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
217fef02 |
5 | use Test::More tests => 11; |
6 | use Test::Exception; |
fde3db1a |
7 | use t::common qw( new_fh ); |
ffed8b01 |
8 | |
217fef02 |
9 | use_ok( 'DBM::Deep' ); |
ffed8b01 |
10 | |
11 | ## |
12 | # testing the various modes of opening a file |
13 | ## |
14 | { |
fde3db1a |
15 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
16 | my %hash; |
2a81bf9e |
17 | my $db = tie %hash, 'DBM::Deep', $filename; |
ffed8b01 |
18 | |
95967a5e |
19 | ok(1, "Tied an hash with an array for params" ); |
ffed8b01 |
20 | } |
21 | |
22 | { |
fde3db1a |
23 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
24 | my %hash; |
25 | my $db = tie %hash, 'DBM::Deep', { |
2a81bf9e |
26 | file => $filename, |
ffed8b01 |
27 | }; |
28 | |
95967a5e |
29 | ok(1, "Tied a hash with a hashref for params" ); |
ffed8b01 |
30 | } |
31 | |
32 | { |
fde3db1a |
33 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
34 | my @array; |
2a81bf9e |
35 | my $db = tie @array, 'DBM::Deep', $filename; |
ffed8b01 |
36 | |
95967a5e |
37 | ok(1, "Tied an array with an array for params" ); |
ffed8b01 |
38 | |
3e97ba2a |
39 | is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" ); |
ffed8b01 |
40 | } |
41 | |
42 | { |
fde3db1a |
43 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
44 | my @array; |
45 | my $db = tie @array, 'DBM::Deep', { |
2a81bf9e |
46 | file => $filename, |
ffed8b01 |
47 | }; |
48 | |
95967a5e |
49 | ok(1, "Tied an array with a hashref for params" ); |
ffed8b01 |
50 | |
3e97ba2a |
51 | is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" ); |
ffed8b01 |
52 | } |
53 | |
fde3db1a |
54 | my ($fh, $filename) = new_fh(); |
e1b265cc |
55 | throws_ok { |
2a81bf9e |
56 | tie my %hash, 'DBM::Deep', [ file => $filename ]; |
e1b265cc |
57 | } qr/Not a hashref/, "Passing an arrayref to TIEHASH fails"; |
ffed8b01 |
58 | |
e1b265cc |
59 | throws_ok { |
2a81bf9e |
60 | tie my @array, 'DBM::Deep', [ file => $filename ]; |
e1b265cc |
61 | } qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails"; |
ffed8b01 |
62 | |
217fef02 |
63 | throws_ok { |
2a81bf9e |
64 | tie my %hash, 'DBM::Deep', undef, file => $filename; |
217fef02 |
65 | } qr/Odd number of parameters/, "Odd number of params to TIEHASH fails"; |
ffed8b01 |
66 | |
217fef02 |
67 | throws_ok { |
2a81bf9e |
68 | tie my @array, 'DBM::Deep', undef, file => $filename; |
217fef02 |
69 | } qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails"; |