2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 67; |
use Test::More tests => 73; |
6 |
|
|
7 |
BEGIN { |
BEGIN { |
8 |
use_ok('DBI'); |
use_ok('DBI'); |
25 |
ok($pwd, "pwd: $pwd"); |
ok($pwd, "pwd: $pwd"); |
26 |
my $index = "$pwd/../data/casket/"; |
my $index = "$pwd/../data/casket/"; |
27 |
|
|
28 |
my $sql = "select * from pgest('$index',?,?,?,?,?,?) as (id text)"; |
my $sql = "select id from pgest('$index',?,?,?,?,?,array['\@id']) as (id text)"; |
29 |
diag "$sql"; |
diag "$sql"; |
30 |
|
|
31 |
my $sth = $dbh->prepare($sql) || die $dbh->errstr(); |
my $sth = $dbh->prepare($sql) || die $dbh->errstr(); |
32 |
ok($sth, "sth"); |
ok($sth, "sth"); |
33 |
|
|
34 |
sub pgest { |
sub pgest { |
35 |
$sth->execute(@_, "{'\@id'}" ) || die $sth->errstr(); |
$sth->execute(@_) || die $sth->errstr(); |
36 |
{ |
{ |
37 |
no warnings; |
no warnings; |
38 |
ok($sth, "execute(".join(",",@_).")"); |
ok($sth, "execute(".join(",",@_).")"); |
39 |
} |
} |
40 |
|
|
41 |
my @arr; |
my @arr; |
42 |
while (my $row = $sth->fetchrow_hashref() ) { |
while (my ($id) = $sth->fetchrow_array() ) { |
43 |
push @arr, $row; |
push @arr, $id; |
44 |
} |
} |
45 |
ok(@arr, "pgest results: ".($#arr + 1)); |
ok(@arr, "pgest results: ".($#arr + 1)); |
46 |
|
|
113 |
|
|
114 |
cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, ($hits - $d), $d), "limit ".($hits - $d)." offset $d"); |
cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, ($hits - $d), $d), "limit ".($hits - $d)." offset $d"); |
115 |
cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check"); |
cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check"); |
116 |
|
|
117 |
|
# test sort |
118 |
|
my @arr_asc = pgest('blade runner', undef, '@id NUMA', undef, undef); |
119 |
|
my @arr_desc = pgest('blade runner', undef, '@id NUMD', undef, undef); |
120 |
|
|
121 |
|
cmp_ok(@arr_asc, '==', @arr_desc, "same number of results"); |
122 |
|
my $errors = 0; |
123 |
|
foreach my $i (0 .. $#arr_asc) { |
124 |
|
my ($a, $b) = ($arr_asc[$i], $arr_desc[$#arr_desc - $i]); |
125 |
|
if ($a ne $b) { |
126 |
|
$errors++; |
127 |
|
diag "element $i: $a != $b"; |
128 |
|
} |
129 |
|
} |
130 |
|
|
131 |
|
cmp_ok($errors, '==', 0, "errors in ordering"); |