/[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 914 - (hide annotations)
Tue Oct 30 20:11:04 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1436 byte(s)
 r1373@llin:  dpavlin | 2007-10-30 21:11:01 +0100
 use KinoSearch::Simple and convert to new Output API

1 dpavlin 914 #!/usr/bin/perl -w
2    
3     use Test::More tests => 14;
4     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     }), "new");
27    
28     ok( $out->init, 'init' );
29    
30     my $ds = {
31     'Source' => {
32     'name' => 'Izvor: ',
33     'search' => [ 'foo' ]
34     },
35     'ID' => {
36     'search' => 'id',
37     },
38     'Array' => {
39     'search' => [ qw/a1 a2 s3 a4 a5/ ],
40     },
41     };
42    
43     throws_ok { $out->add( ) } qr/need id/, 'add without params';
44     throws_ok { $out->add( 42 ) } qr/need ds/, 'add without ds';
45    
46     ok( $out->add( 42, $ds ), 'add 42' );
47    
48     ok( $out->add( 99, { foo => { search => 'bar' } } ), 'add 99' );
49    
50     ok( $out->add( 100, { foo => { search => [ qw/foo bar baz/ ] } } ), 'add 100' );
51    
52     ok( -e $out->path, "created $path" );
53    
54     ok( my $index = $out->index, 'have index' );
55    
56     diag $out->path," eq ",$path;
57     cmp_ok( $out->path, 'eq', $path, 'path' );
58    
59     my $query_string = 'foo';
60    
61     my $total_hits = $index->search(
62     query => $query_string,
63     offset => 0,
64     num_wanted => 10,
65     );
66    
67     diag "Total hits: $total_hits\n";
68     while ( my $hit = $index->fetch_hit_hashref ) {
69     diag dump($hit);
70     }
71    
72     ok( $out->finish, 'finish' );
73    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26