use Test::More;
use Test::Exception;
use t::common qw( new_dbm );
+use Scalar::Util qw( reftype );
use_ok( 'DBM::Deep' );
# Test autovivification
$db->{unknown}{bar} = 1;
ok( $db->{unknown}, 'Autovivified hash exists' );
+ is( reftype($db->{unknown}), 'HASH', "... and it's a HASH" );
cmp_ok( $db->{unknown}{bar}, '==', 1, 'And the value stored is there' );
# Test failures
} qr/Cannot use an undefined hash key/, "EXISTS fails on an undefined key";
}
+{
+ # RT# 50541 (reported by Peter Scott)
+ # clear() leaves one key unless there's only one
+ my $dbm_factory = new_dbm();
+ while ( my $dbm_maker = $dbm_factory->() ) {
+ my $db = $dbm_maker->();
+
+ $db->{block} = { };
+ $db->{critical} = { };
+ $db->{minor} = { };
+
+ cmp_ok( scalar(keys( %$db )), '==', 3, "Have 3 keys" );
+
+ $db->clear;
+
+ cmp_ok( scalar(keys( %$db )), '==', 0, "clear clears everything" );
+ }
+}
+
done_testing;