/[pgestraier]/trunk/t/pgest.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/pgest.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 30 by dpavlin, Fri May 27 21:06:01 2005 UTC revision 31 by dpavlin, Wed Jul 6 14:47:56 2005 UTC
# Line 25  if ($pwd !~ m#^/#) { Line 25  if ($pwd !~ m#^/#) {
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 * from pgest('$index',?,?,?,?,?,?) 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();
# Line 42  sub pgest { Line 42  sub pgest {
42          while (my $row = $sth->fetchrow_hashref() ) {          while (my $row = $sth->fetchrow_hashref() ) {
43                  push @arr, $row;                  push @arr, $row;
44          }          }
45          ok(@arr, "results ".($#arr + 1));          ok(@arr, "pgest results: ".($#arr + 1));
46    
47          return @arr;          return @arr;
48  }  }
# Line 53  sub estcmd { Line 53  sub estcmd {
53    
54          my $cmd = "estcmd search ";          my $cmd = "estcmd search ";
55          $cmd .= " -attr '$attr' " if ($attr);          $cmd .= " -attr '$attr' " if ($attr);
56            $cmd .= " -max 999999 ";                # why do I need this?
57          $q ||= '';          $q ||= '';
58          $cmd .= "$index '$q'";          $cmd .= "$index '$q'";
59          diag $cmd;          diag $cmd;
60    
61          open(my $fh, "$cmd |") || die "cmd: $!";          open(my $fh, "$cmd |") || die "cmd: $!";
62            my $del = <$fh>;
63            chomp($del);
64          while(<$fh>) {          while(<$fh>) {
65                  if (/^HIT=(\d+)/) {                  last if (/^\Q$del\E/);
                         return $1;  
                 }  
66          }          }
67          return undef;          my @arr;
68            while(<$fh>) {
69                    chomp;
70                    last if (/^\Q$del\E/);
71                    push @arr, $_;
72            }
73    
74            return @arr;
75  }  }
76    
77  # test simple query  # test simple query
# Line 73  foreach my $q (qw(blade runner Philip k. Line 81  foreach my $q (qw(blade runner Philip k.
81    
82          diag "$hits hits";          diag "$hits hits";
83    
84          cmp_ok(scalar pgest($q, '', 0, 0), '==', $hits, 'blade runner');          cmp_ok(scalar pgest($q, '', undef, 0, 0), '==', $hits, 'blade runner');
85  }  }
86    
87  # test attr query  # test attr query
# Line 83  foreach my $q (('@title STRINC Blade Run Line 91  foreach my $q (('@title STRINC Blade Run
91    
92          diag "$hits hits";          diag "$hits hits";
93    
94          cmp_ok(scalar pgest('', $q, 0, 0), '==', $hits, 'blade runner');          cmp_ok(scalar pgest(undef, $q, undef, 0, 0), '==', $hits, 'blade runner');
95  }  }
96    
97  diag "Error handling test follows, ignore messages...";  diag "Error handling test follows, ignore messages...";
98  # test NULL handling  # test NULL handling
99  ok(! $dbh->do(qq`select * from pgest(null, '', '', 0, 0, array['\@id']) as (id text)`), "null index_path");  ok(! $dbh->do(qq`select * from pgest(null, '', '', null, 0, 0, array['\@id']) as (id text)`), "null index_path");
100  ok(my $hits = pgest('blade runner', '', 0, 0), "test search");  ok(my $hits = pgest('blade runner', '', undef, 0, 0), "test search");
101  cmp_ok($hits, '==', pgest('blade runner', undef, 0, 0), "null attr");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, 0, 0), "null attr");
102  cmp_ok($hits, '==', pgest('blade runner', '', undef, 0), "null limit");  cmp_ok($hits, '==', pgest('blade runner', '', undef, undef, 0), "null limit");
103  cmp_ok($hits, '==', pgest('blade runner', '', 0, undef), "null offset");  cmp_ok($hits, '==', pgest('blade runner', '', undef, 0, undef), "null offset");
104  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "null optional");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "null optional");
105    
106  # test limit, offset and global mess  # test limit, offset and global mess
107  my $d = int($hits / 3);  my $d = int($hits / 3);
108  cmp_ok($d, '==', pgest('blade runner',undef, $d, undef), "limit $d");  cmp_ok($d, '==', pgest('blade runner',undef, undef, $d, undef), "limit $d");
109  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");
110    
111  cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, $d), "offset $d");  cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, undef, $d), "offset $d");
112  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");
113    
114  cmp_ok(($hits - $d - $d), '==', pgest('blade runner',undef, ($hits - $d), $d), "limit $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), "check");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");

Legend:
Removed from v.30  
changed lines
  Added in v.31

  ViewVC Help
Powered by ViewVC 1.1.26