--- t/10-xs.t 2008/08/18 17:26:01 15 +++ t/10-tci.t 2008/09/21 14:24:22 36 @@ -5,7 +5,7 @@ use blib; -use Test::More tests => 15; +use Test::More tests => 36; use Test::Exception; use Data::Dump qw/dump/; @@ -13,7 +13,7 @@ use_ok( 'Search::TokyoDystopia' ); } -my $path = 'casket'; +my $path = 'casket-idb'; cmp_ok( $Search::TokyoDystopia::debug, '==', 0, '$debug' ); @@ -33,7 +33,7 @@ ok( tcidbsetfwmmax( $idb, 0 ), 'tcidbsetfwmmax' ); -ok( tcidbopen( $idb, $path, IDBOWRITER | IDBOCREAT ), "tcidbopen $path" ); +ok( tcidbopen( $idb, $path, IDBOWRITER | IDBOCREAT | IDBOTRUNC ), "tcidbopen $path" ); ok( tcidbclose( $idb ), 'tcidbclose' ); @@ -43,4 +43,47 @@ ok( tcidbout( $idb, 1, ), 'tcidbout' ); +ok( tcidbput( $idb, 42, 'some data' ), 'tcidbput again' ); +is( tcidbget( $idb, 42 ), 'some data', 'tcidbget' ); +ok( ! tcidbget( $idb, 1 ), 'tcidbget non-existing' ); + +is_deeply( tcidbsearch( $idb, 'some', IDBSSUBSTR ), [ 42 ], 'tcidbsearch' ); +ok( tcidbput( $idb, 65536, 'some more data' ), 'tcidbput more data' ); +is_deeply( tcidbsearch( $idb, 'some', IDBSSUBSTR ), [ 42, 65536 ], 'tcidbsearch' ); + +is_deeply( tcidbsearch2( $idb, 'some' ), [ 42, 65536 ], 'tcidbsearch2' ); + +ok( tcidbiterinit( $idb ), 'tcidbiterinit' ); + +my @ids; + +while ( my $id = tcidbiternext( $idb ) ) { + ok( $id, "tcidbiternext $id" ); + push @ids, $id; +} + +# order is not defined, so we need to sort it +is_deeply( [ sort @ids ], [ 42, 65536 ], 'all records' ); + +ok( tcidbsync( $idb ), 'tcidbsync' ); + +ok( tcidboptimize( $idb ), 'tcidboptimize' ); + +my $copy_path = $path . '-copy'; + +ok( tcidbcopy( $idb, $copy_path ), "tcidbcopy $copy_path" ); +ok( -e $copy_path, 'copy exists' ); + +is( tcidbpath( $idb ), $path, 'tcidbpath' ); + +is( tcidbrnum( $idb ), 2, 'tcidbrnum' ); + +ok( my $file_size = tcidbfsiz( $idb ), 'tcidbfsiz' ); + +ok( tcidbvanish( $idb ), 'tcidbvanish' ); + +is( tcidbrnum( $idb ), 0, 'tcidbrnum' ); + +cmp_ok( tcidbfsiz( $idb ), '<', $file_size, 'tcidbfsiz' ); + diag tcidberrmsg( tcidbecode( $idb ) );