--- trunk/t/pgest.t 2005/07/06 14:34:10 30 +++ trunk/t/pgest.t 2005/07/06 14:47:56 31 @@ -25,7 +25,7 @@ ok($pwd, "pwd: $pwd"); my $index = "$pwd/../data/casket/"; -my $sql = "select * from pgest('$index',?,?,?,?,?) as (id text)"; +my $sql = "select * from pgest('$index',?,?,?,?,?,?) as (id text)"; diag "$sql"; my $sth = $dbh->prepare($sql) || die $dbh->errstr(); @@ -42,7 +42,7 @@ while (my $row = $sth->fetchrow_hashref() ) { push @arr, $row; } - ok(@arr, "results ".($#arr + 1)); + ok(@arr, "pgest results: ".($#arr + 1)); return @arr; } @@ -53,17 +53,25 @@ my $cmd = "estcmd search "; $cmd .= " -attr '$attr' " if ($attr); + $cmd .= " -max 999999 "; # why do I need this? $q ||= ''; $cmd .= "$index '$q'"; diag $cmd; open(my $fh, "$cmd |") || die "cmd: $!"; + my $del = <$fh>; + chomp($del); while(<$fh>) { - if (/^HIT=(\d+)/) { - return $1; - } + last if (/^\Q$del\E/); } - return undef; + my @arr; + while(<$fh>) { + chomp; + last if (/^\Q$del\E/); + push @arr, $_; + } + + return @arr; } # test simple query @@ -73,7 +81,7 @@ diag "$hits hits"; - cmp_ok(scalar pgest($q, '', 0, 0), '==', $hits, 'blade runner'); + cmp_ok(scalar pgest($q, '', undef, 0, 0), '==', $hits, 'blade runner'); } # test attr query @@ -83,25 +91,25 @@ diag "$hits hits"; - cmp_ok(scalar pgest('', $q, 0, 0), '==', $hits, 'blade runner'); + cmp_ok(scalar pgest(undef, $q, undef, 0, 0), '==', $hits, 'blade runner'); } diag "Error handling test follows, ignore messages..."; # test NULL handling -ok(! $dbh->do(qq`select * from pgest(null, '', '', 0, 0, array['\@id']) as (id text)`), "null index_path"); -ok(my $hits = pgest('blade runner', '', 0, 0), "test search"); -cmp_ok($hits, '==', pgest('blade runner', undef, 0, 0), "null attr"); -cmp_ok($hits, '==', pgest('blade runner', '', undef, 0), "null limit"); -cmp_ok($hits, '==', pgest('blade runner', '', 0, undef), "null offset"); -cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "null optional"); +ok(! $dbh->do(qq`select * from pgest(null, '', '', null, 0, 0, array['\@id']) as (id text)`), "null index_path"); +ok(my $hits = pgest('blade runner', '', undef, 0, 0), "test search"); +cmp_ok($hits, '==', pgest('blade runner', undef, undef, 0, 0), "null attr"); +cmp_ok($hits, '==', pgest('blade runner', '', undef, undef, 0), "null limit"); +cmp_ok($hits, '==', pgest('blade runner', '', undef, 0, undef), "null offset"); +cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "null optional"); # test limit, offset and global mess my $d = int($hits / 3); -cmp_ok($d, '==', pgest('blade runner',undef, $d, undef), "limit $d"); -cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check"); +cmp_ok($d, '==', pgest('blade runner',undef, undef, $d, undef), "limit $d"); +cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check"); -cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, $d), "offset $d"); -cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check"); +cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, undef, $d), "offset $d"); +cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check"); -cmp_ok(($hits - $d - $d), '==', pgest('blade runner',undef, ($hits - $d), $d), "limit $d offset $d"); -cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check"); +cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, ($hits - $d), $d), "limit ".($hits - $d)." offset $d"); +cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");