--- trunk/t/pgest.t 2005/07/06 14:47:56 31 +++ trunk/t/pgest.t 2005/07/06 15:15:04 32 @@ -2,7 +2,7 @@ use strict; -use Test::More tests => 67; +use Test::More tests => 73; BEGIN { use_ok('DBI'); @@ -25,22 +25,22 @@ ok($pwd, "pwd: $pwd"); my $index = "$pwd/../data/casket/"; -my $sql = "select * from pgest('$index',?,?,?,?,?,?) as (id text)"; +my $sql = "select id from pgest('$index',?,?,?,?,?,array['\@id']) as (id text)"; diag "$sql"; my $sth = $dbh->prepare($sql) || die $dbh->errstr(); ok($sth, "sth"); sub pgest { - $sth->execute(@_, "{'\@id'}" ) || die $sth->errstr(); + $sth->execute(@_) || die $sth->errstr(); { no warnings; ok($sth, "execute(".join(",",@_).")"); } my @arr; - while (my $row = $sth->fetchrow_hashref() ) { - push @arr, $row; + while (my ($id) = $sth->fetchrow_array() ) { + push @arr, $id; } ok(@arr, "pgest results: ".($#arr + 1)); @@ -113,3 +113,19 @@ 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"); + +# test sort +my @arr_asc = pgest('blade runner', undef, '@id NUMA', undef, undef); +my @arr_desc = pgest('blade runner', undef, '@id NUMD', undef, undef); + +cmp_ok(@arr_asc, '==', @arr_desc, "same number of results"); +my $errors = 0; +foreach my $i (0 .. $#arr_asc) { + my ($a, $b) = ($arr_asc[$i], $arr_desc[$#arr_desc - $i]); + if ($a ne $b) { + $errors++; + diag "element $i: $a != $b"; + } +} + +cmp_ok($errors, '==', 0, "errors in ordering");