Created a CURRENT per mst's recommendation
[dbsrgits/DBM-Deep.git] / CURRENT / t / 21_tie_access.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 7;
6 use Test::Exception;
7 use t::common qw( new_fh );
8
9 use_ok( 'DBM::Deep' );
10
11 my ($fh, $filename) = new_fh();
12
13 {
14     my %hash;
15     tie %hash, 'DBM::Deep', $filename;
16
17     $hash{key1} = 'value';
18     is( $hash{key1}, 'value', 'Set and retrieved key1' );
19 }
20
21 {
22     my %hash;
23     tie %hash, 'DBM::Deep', $filename;
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
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 }
39
40 {
41     my ($fh, $filename) = new_fh();
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 }