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