From: rkinyon Date: Wed, 22 Mar 2006 12:46:58 +0000 (+0000) Subject: Added basic array test structure X-Git-Tag: 0-99_01~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=361dba512bb417420aa8b88778a2f2a0ef9076bf;p=dbsrgits%2FDBM-Deep.git Added basic array test structure --- diff --git a/t/lib/Test1.pm b/t/lib/Test1.pm index 1cbc823..adfe9ba 100644 --- a/t/lib/Test1.pm +++ b/t/lib/Test1.pm @@ -8,13 +8,13 @@ use warnings; use base 'TestBase'; use base 'TestSimpleHash'; -sub setup : Test(startup) { - my $self = shift; - - $self->{db} = DBM::Deep->new( $self->new_file ); - - return; -} +#sub setup : Test(startup) { +# my $self = shift; +# +# $self->{db} = DBM::Deep->new( $self->new_file ); +# +# return; +#} 1; __END__ diff --git a/t/lib/Test2.pm b/t/lib/Test2.pm new file mode 100644 index 0000000..b4cde50 --- /dev/null +++ b/t/lib/Test2.pm @@ -0,0 +1,20 @@ +package Test2; + +use 5.6.0; + +use strict; +use warnings; + +use base 'TestBase'; +use base 'TestSimpleArray'; + +#sub setup : Test(startup) { +# my $self = shift; +# +# $self->{db} = DBM::Deep->new( $self->new_file ); +# +# return; +#} + +1; +__END__ diff --git a/t/lib/TestBase.pm b/t/lib/TestBase.pm index 950b800..95ee9fb 100644 --- a/t/lib/TestBase.pm +++ b/t/lib/TestBase.pm @@ -5,14 +5,31 @@ use 5.6.0; use strict; use warnings; +use Fcntl qw( :flock ); use File::Path (); use File::Temp (); -use Fcntl qw( :flock ); +use Scalar::Util (); use base 'Test::Class'; use DBM::Deep; +sub setup_db : Test(startup) { + my $self = shift; + + my $data = ($self->{data} ||= {}); + + my $r = Scalar::Util::reftype( $data ); + my $type = $r eq 'HASH' ? DBM::Deep->TYPE_HASH : DBM::Deep->TYPE_ARRAY; + + $self->{db} = DBM::Deep->new({ + file => $self->new_file, + type => $type, + }); + + return; +} + sub setup_dir : Test(startup) { my $self = shift; diff --git a/t/lib/TestSimpleArray.pm b/t/lib/TestSimpleArray.pm new file mode 100644 index 0000000..1c0d55b --- /dev/null +++ b/t/lib/TestSimpleArray.pm @@ -0,0 +1,51 @@ +package TestSimpleArray; + +use 5.6.0; + +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use base 'TestBase'; + +sub A_assignment : Test( 37 ) { + my $self = shift; + my $db = $self->{db}; + + my @keys = 0 .. $#{$self->{data}}; + + push @keys, $keys[0] while @keys < 5; + + cmp_ok( @$db, '==', 0 ); + + foreach my $k ( @keys[0..4] ) { + ok( !exists $db->[$k] ); + ok( !$db->exists( $k ) ); + } + + $db->[$keys[0]] = $self->{data}[$keys[1]]; + $db->push( $self->{data}[$keys[2]] ); + $db->put( $keys[2] => $self->{data}[$keys[3]] ); + $db->store( $keys[3] => $self->{data}[$keys[4]] ); + $db->unshift( $self->{data}[$keys[0]] ); + + foreach my $k ( @keys[0..4] ) { + ok( $db->exists( $k ) ); + ok( exists $db->[$k] ); + + is( $db->[$k], $self->{data}[$k] ); + is( $db->get($k), $self->{data}[$k] ); + is( $db->fetch($k), $self->{data}[$k] ); + } + + if ( @keys > 5 ) { + $db->[$_] = $self->{data}[$_] for @keys[5..$#keys]; + } + + cmp_ok( @$db, '==', @keys ); +} + +1; +__END__ diff --git a/t/lib/TestSimpleHash.pm b/t/lib/TestSimpleHash.pm index 7e036c6..fdfbeb0 100644 --- a/t/lib/TestSimpleHash.pm +++ b/t/lib/TestSimpleHash.pm @@ -18,8 +18,6 @@ sub A_assignment : Test( 23 ) { push @keys, $keys[0] while @keys < 3; - #die "@keys\n"; - cmp_ok( keys %$db, '==', 0 ); foreach my $k ( @keys[0..2] ) { diff --git a/t/run.t b/t/run.t index 39ecc93..cdd89f3 100644 --- a/t/run.t +++ b/t/run.t @@ -8,6 +8,7 @@ use lib 't/lib'; use DBM::Deep; use Test1; +use Test2; my $test1 = Test1->new( data => { @@ -24,7 +25,13 @@ my $test2 = Test1->new( data => \%test2, ); +my $test3 = Test2->new( + data => [ + 1 .. 5, + ], +); + Test::Class->runtests( $test1, -# $test2, + $test3, );