From: rkinyon Date: Wed, 22 Mar 2006 02:31:24 +0000 (+0000) Subject: Completed transcription of 02_hash.t X-Git-Tag: 0-99_01~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bcc9f3bdaefaeaf6d538274693c8e6341f49acb9;p=dbsrgits%2FDBM-Deep.git Completed transcription of 02_hash.t --- diff --git a/t/lib/TestSimpleHash.pm b/t/lib/TestSimpleHash.pm index 385db95..4dd36eb 100644 --- a/t/lib/TestSimpleHash.pm +++ b/t/lib/TestSimpleHash.pm @@ -74,5 +74,70 @@ sub D_firstkey : Test( 1 ) { is_deeply( $temp, $self->{data} ); } +sub E_delete : Test( 12 ) { + my $self = shift; + my $db = $self->{db}; + + my @keys = keys %{$self->{data}}; + cmp_ok( scalar(keys %$db), '==', scalar(@keys) ); + + my $key1 = $keys[0]; + ok( exists $db->{$key1} ); + is( $db->{$key1}, $self->{data}{$key1} ); + is( delete $db->{$key1}, $self->{data}{$key1} ); + ok( !exists $db->{$key1} ); + cmp_ok( keys %$db, '==', @keys - 1 ); + + my $key2 = $keys[1]; + ok( exists $db->{$key2} ); + is( $db->{$key2}, $self->{data}{$key2} ); + is( $db->delete( $key2 ), $self->{data}{$key2} ); + ok( !exists $db->{$key2} ); + cmp_ok( keys %$db, '==', @keys - 2 ); + + @{$db}{ @keys[0,1] } = @{$self->{data}}{@keys[0,1]}; + + cmp_ok( scalar(keys %$db), '==', scalar(@keys) ); +} + +sub F_clear : Test( 3 ) { + my $self = shift; + my $db = $self->{db}; + + my @keys = keys %{$self->{data}}; + cmp_ok( scalar(keys %$db), '==', scalar(@keys) ); + + %$db = (); + + cmp_ok( keys %$db, '==', 0 ); + + %$db = %{$self->{data}}; + cmp_ok( scalar(keys %$db), '==', scalar(@keys) ); +} + +sub G_reassign_and_close : Test( 4 ) { + my $self = shift; + + my @keys = keys %{$self->{data}}; + + my $key1 = $keys[0]; + + my $long_value = 'long value' x 100; + $self->{db}{$key1} = $long_value; + is( $self->{db}{$key1}, $long_value ); + + my $filename = $self->{db}->_root->{file}; + undef $self->{db}; + + $self->{db} = DBM::Deep->new( $filename ); + + is( $self->{db}{$key1}, $long_value ); + + $self->{db}{$key1} = $self->{data}{$key1}; + is( $self->{db}{$key1}, $self->{data}{$key1} ); + + cmp_ok( keys %{$self->{db}}, '==', @keys ); +} + 1; __END__