Flushing problems fixed
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
2a81bf9e 5use Test::More tests => 7;
ffed8b01 6use Test::Exception;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
fde3db1a 11my ($fh, $filename) = new_fh();
ffed8b01 12
13{
14 my %hash;
2a81bf9e 15 tie %hash, 'DBM::Deep', $filename;
ffed8b01 16
17 $hash{key1} = 'value';
18 is( $hash{key1}, 'value', 'Set and retrieved key1' );
f1879fdc 19 tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
ffed8b01 20}
21
22{
23 my %hash;
2a81bf9e 24 tie %hash, 'DBM::Deep', $filename;
ffed8b01 25
26 is( $hash{key1}, 'value', 'Set and retrieved key1' );
27
28 is( keys %hash, 1, "There's one key so far" );
29 ok( exists $hash{key1}, "... and it's key1" );
f1879fdc 30 tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
ffed8b01 31}
32
2a8ac017 33{
34 throws_ok {
35 tie my @array, 'DBM::Deep', {
36 file => $filename,
37 type => DBM::Deep->TYPE_ARRAY,
38 };
f1879fdc 39 tied( @array )->_get_self->_engine->storage->close( tied( @array )->_get_self );
2a8ac017 40 } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
41}
ffed8b01 42
2a81bf9e 43{
fde3db1a 44 my ($fh, $filename) = new_fh();
45f047f8 45 my $db = DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
2a81bf9e 46
47 throws_ok {
48 tie my %hash, 'DBM::Deep', {
49 file => $filename,
50 type => DBM::Deep->TYPE_HASH,
51 };
52 } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
f1879fdc 53 $db->_get_self->_engine->storage->close( $db->_get_self );
2a81bf9e 54}