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