/[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 949 - (hide annotations)
Thu Nov 1 00:16:48 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1706 byte(s)
 r1433@llin:  dpavlin | 2007-10-31 22:48:02 +0100
 HUGE swiping changes to implement new testing architecture
 based on all new WebPAC::Test module which makes
 test writing a joy

1 dpavlin 914 #!/usr/bin/perl -w
2    
3 dpavlin 949 use strict;
4 dpavlin 914 use blib;
5    
6 dpavlin 949 use Test::More tests => 35;
7    
8     use KinoSearch;
9     use Encode qw/decode/;
10    
11 dpavlin 914 BEGIN {
12 dpavlin 949 use_ok( 'WebPAC::Test' );
13 dpavlin 914 use_ok( 'WebPAC::Output::KinoSearch' );
14     }
15    
16     my $path = "$abs_path/kino/";
17    
18     ok(my $out = new WebPAC::Output::KinoSearch({
19     path => $path,
20     database => 'test',
21 dpavlin 919 clean => 1,
22 dpavlin 949 %LOG
23 dpavlin 914 }), "new");
24    
25     ok( $out->init, 'init' );
26    
27     my $ds = {
28     'Source' => {
29     'name' => 'Izvor: ',
30 dpavlin 949 'search' => [ 'tko zna' ]
31 dpavlin 914 },
32     'ID' => {
33     'search' => 'id',
34     },
35     'Array' => {
36     'search' => [ qw/a1 a2 s3 a4 a5/ ],
37     },
38 dpavlin 949 'foo' => {
39     'search' => [ 'foo' ],
40     },
41 dpavlin 914 };
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 dpavlin 949 my @strange = ( qw/èajðinica odma¹æivanje ¾abokreèina ¹uma/ );
49 dpavlin 914
50 dpavlin 949 ok( $out->add( 99, { foo => { search => [ @strange ] } } ), 'add 99' );
51    
52 dpavlin 914 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 dpavlin 949 sub test_search {
62     my ( $query_string, $expected_hits ) = @_;
63 dpavlin 914
64 dpavlin 949 my $total_hits = $index->search(
65     query => $query_string,
66     offset => 0,
67     num_wanted => 10,
68     );
69    
70     ok( $total_hits, "search '$query_string'" );
71    
72     diag "Total hits: $total_hits\n" if $debug;
73    
74     cmp_ok( $total_hits, '==', $expected_hits, 'total_hits' );
75    
76     while ( my $hit = $index->fetch_hit_hashref ) {
77     ok( $hit, 'hit' );
78     ok( $hit->{foo} =~ m/èajðinica/, 'utf-8 conversion' );
79     diag dump($hit) if $debug;
80     }
81    
82 dpavlin 914 }
83    
84 dpavlin 949 test_search( 'foo', 2 );
85    
86     test_search( $_, 1 ) foreach @strange;
87    
88 dpavlin 914 ok( $out->finish, 'finish' );
89    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26