/[webpac2]/trunk/t/5-output-kinosearch.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

Annotation of /trunk/t/5-output-kinosearch.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 919 - (hide annotations)
Tue Oct 30 22:07:11 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1487 byte(s)
 r1383@llin:  dpavlin | 2007-10-30 23:07:09 +0100
 added clean to start with empty index

1 dpavlin 914 #!/usr/bin/perl -w
2    
3 dpavlin 919 use Test::More tests => 20;
4 dpavlin 914 use Test::Exception;
5     use Cwd qw/abs_path/;
6     use KinoSearch;
7     use File::Slurp;
8     use Data::Dump qw/dump/;
9     use blib;
10     use strict;
11    
12     BEGIN {
13     use_ok( 'WebPAC::Output::KinoSearch' );
14     }
15    
16     my $debug = shift @ARGV;
17    
18     ok(my $abs_path = abs_path($0), "abs_path");
19     $abs_path =~ s#/[^/]*$#/#; #
20     diag "abs_path: $abs_path";
21     my $path = "$abs_path/kino/";
22    
23     ok(my $out = new WebPAC::Output::KinoSearch({
24     path => $path,
25     database => 'test',
26 dpavlin 919 clean => 1,
27     debug => $debug,
28 dpavlin 914 }), "new");
29    
30     ok( $out->init, 'init' );
31    
32     my $ds = {
33     'Source' => {
34     'name' => 'Izvor: ',
35     'search' => [ 'foo' ]
36     },
37     'ID' => {
38     'search' => 'id',
39     },
40     'Array' => {
41     'search' => [ qw/a1 a2 s3 a4 a5/ ],
42     },
43     };
44    
45     throws_ok { $out->add( ) } qr/need id/, 'add without params';
46     throws_ok { $out->add( 42 ) } qr/need ds/, 'add without ds';
47    
48     ok( $out->add( 42, $ds ), 'add 42' );
49    
50     ok( $out->add( 99, { foo => { search => 'bar' } } ), 'add 99' );
51    
52     ok( $out->add( 100, { foo => { search => [ qw/foo bar baz/ ] } } ), 'add 100' );
53    
54     ok( -e $out->path, "created $path" );
55    
56     ok( my $index = $out->index, 'have index' );
57    
58     diag $out->path," eq ",$path;
59     cmp_ok( $out->path, 'eq', $path, 'path' );
60    
61     my $query_string = 'foo';
62    
63     my $total_hits = $index->search(
64     query => $query_string,
65     offset => 0,
66     num_wanted => 10,
67     );
68    
69     diag "Total hits: $total_hits\n";
70     while ( my $hit = $index->fetch_hit_hashref ) {
71 dpavlin 919 ok( $hit, 'hit' );
72 dpavlin 914 diag dump($hit);
73     }
74    
75     ok( $out->finish, 'finish' );
76    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26