--- trunk/t/5-output-kinosearch.t 2007/11/01 00:16:46 948 +++ trunk/t/5-output-kinosearch.t 2007/11/01 00:16:48 949 @@ -1,30 +1,25 @@ #!/usr/bin/perl -w -use Test::More tests => 15; -use Test::Exception; -use Cwd qw/abs_path/; -use KinoSearch; -use File::Slurp; -use Data::Dump qw/dump/; -use blib; use strict; +use blib; + +use Test::More tests => 35; + +use KinoSearch; +use Encode qw/decode/; BEGIN { +use_ok( 'WebPAC::Test' ); use_ok( 'WebPAC::Output::KinoSearch' ); } -my $debug = shift @ARGV; - -ok(my $abs_path = abs_path($0), "abs_path"); -$abs_path =~ s#/[^/]*$#/#; # -diag "abs_path: $abs_path"; my $path = "$abs_path/kino/"; ok(my $out = new WebPAC::Output::KinoSearch({ path => $path, database => 'test', clean => 1, - debug => $debug, + %LOG }), "new"); ok( $out->init, 'init' ); @@ -32,7 +27,7 @@ my $ds = { 'Source' => { 'name' => 'Izvor: ', - 'search' => [ 'foo' ] + 'search' => [ 'tko zna' ] }, 'ID' => { 'search' => 'id', @@ -40,6 +35,9 @@ 'Array' => { 'search' => [ qw/a1 a2 s3 a4 a5/ ], }, + 'foo' => { + 'search' => [ 'foo' ], + }, }; throws_ok { $out->add( ) } qr/need id/, 'add without params'; @@ -47,7 +45,9 @@ ok( $out->add( 42, $ds ), 'add 42' ); -ok( $out->add( 99, { foo => { search => 'bar' } } ), 'add 99' ); +my @strange = ( qw/čajšinica odma¹ęivanje ¾abokrečina ¹uma/ ); + +ok( $out->add( 99, { foo => { search => [ @strange ] } } ), 'add 99' ); ok( $out->add( 100, { foo => { search => [ qw/foo bar baz/ ] } } ), 'add 100' ); @@ -58,19 +58,32 @@ diag $out->path," eq ",$path; cmp_ok( $out->path, 'eq', $path, 'path' ); -my $query_string = 'foo'; +sub test_search { + my ( $query_string, $expected_hits ) = @_; + + my $total_hits = $index->search( + query => $query_string, + offset => 0, + num_wanted => 10, + ); + + ok( $total_hits, "search '$query_string'" ); + + diag "Total hits: $total_hits\n" if $debug; + + cmp_ok( $total_hits, '==', $expected_hits, 'total_hits' ); + + while ( my $hit = $index->fetch_hit_hashref ) { + ok( $hit, 'hit' ); + ok( $hit->{foo} =~ m/čajšinica/, 'utf-8 conversion' ); + diag dump($hit) if $debug; + } -my $total_hits = $index->search( - query => $query_string, - offset => 0, - num_wanted => 10, -); - -diag "Total hits: $total_hits\n"; -while ( my $hit = $index->fetch_hit_hashref ) { - ok( $hit, 'hit' ); - diag dump($hit); } +test_search( 'foo', 2 ); + +test_search( $_, 1 ) foreach @strange; + ok( $out->finish, 'finish' );