From: rkinyon Date: Tue, 21 Mar 2006 15:47:27 +0000 (+0000) Subject: More tests added X-Git-Tag: 0-99_01~50 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa7ad9c2bd80912f6e4292c30d12cca75a660ac5;p=dbsrgits%2FDBM-Deep.git More tests added --- diff --git a/t/lib/TestBase.pm b/t/lib/TestBase.pm index 5696992..950b800 100644 --- a/t/lib/TestBase.pm +++ b/t/lib/TestBase.pm @@ -16,7 +16,7 @@ use DBM::Deep; sub setup_dir : Test(startup) { my $self = shift; - $self->{workdir} = File::Temp::tempdir(); + $self->{workdir} ||= File::Temp::tempdir(); return; } @@ -24,6 +24,8 @@ sub setup_dir : Test(startup) { sub new_file { my $self = shift; + $self->setup_dir; + my ($fh, $filename) = File::Temp::tempfile( 'tmpXXXX', DIR => $self->{workdir}, CLEANUP => 1, ); diff --git a/t/lib/TestSimpleHash.pm b/t/lib/TestSimpleHash.pm index a404ff7..385db95 100644 --- a/t/lib/TestSimpleHash.pm +++ b/t/lib/TestSimpleHash.pm @@ -10,21 +10,69 @@ use Test::Exception; use base 'TestBase'; -sub assignment_direct : Test( no_plan ) { +sub A_assignment : Test( no_plan ) { my $self = shift; - my $db = $self->{db}; + + my $rotate = 0; + while ( my ($k,$v) = each %{$self->{data}} ) { - $db->{$k} = $v; + $rotate = ++$rotate % 3; + + if ( $rotate == 0 ) { + $db->{$k} = $v; + } + elsif ( $rotate == 1 ) { + $db->put( $k => $v ); + } + else { + $db->store( $k => $v ); + } ok( $db->exists( $k ) ); ok( exists $db->{$k} ); + is( $db->{$k}, $v ); is( $db->get($k), $v ); is( $db->fetch($k), $v ); - is( $db->{$k}, $v ); } } +sub B_check_keys : Test( 1 ) { + my $self = shift; + my $db = $self->{db}; + + my @control = sort keys %{$self->{data}}; + my @test1 = sort keys %$db; + is_deeply( \@test1, \@control ); +} + +sub C_each : Test( 1 ) { + my $self = shift; + my $db = $self->{db}; + + my $temp = {}; + while ( my ($k,$v) = each %$db ) { + $temp->{$k} = $v; + } + + is_deeply( $temp, $self->{data} ); +} + +sub D_firstkey : Test( 1 ) { + my $self = shift; + my $db = $self->{db}; + + my $temp = {}; + + my $key = $db->first_key; + while ( $key ) { + $temp->{$key} = $db->get( $key ); + $key = $db->next_key( $key ); + } + + is_deeply( $temp, $self->{data} ); +} + 1; __END__