#!/usr/bin/perl -w
-use Test::More tests => 20;
-use Test::Exception;
-use Cwd qw/abs_path/;
-use KinoSearch;
-use File::Slurp;
-use Data::Dump qw/dump/;
-use blib;
use strict;
+use lib 'lib';
+
+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' );
my $ds = {
'Source' => {
'name' => 'Izvor: ',
- 'search' => [ 'foo' ]
+ 'search' => [ 'tko zna' ]
},
'ID' => {
'search' => 'id',
'Array' => {
'search' => [ qw/a1 a2 s3 a4 a5/ ],
},
+ 'foo' => {
+ 'search' => [ 'foo' ],
+ },
};
throws_ok { $out->add( ) } qr/need id/, 'add without params';
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' );
diag $out->path," eq ",$path;
cmp_ok( $out->path, 'eq', $path, 'path' );
-my $query_string = 'foo';
-
-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);
+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;
+ }
+
}
+test_search( 'foo', 2 );
+
+test_search( $_, 1 ) foreach @strange;
+
ok( $out->finish, 'finish' );