/[SWISH-PlusPlus]/trunk/t/01swish.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/01swish.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (hide annotations)
Sun Dec 5 21:50:47 2004 UTC (19 years, 4 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1850 byte(s)
remove debugging output

1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4    
5 dpavlin 16 use Test::More tests => 47;
6 dpavlin 2 use Test::Exception;
7     use blib;
8    
9     BEGIN {
10     use_ok('SWISH::PlusPlus')
11     };
12    
13     my $i;
14    
15 dpavlin 10 throws_ok { SWISH::PlusPlus->new() } qr/index_dir/, "need index_dir";
16 dpavlin 2
17     ## FIXME
18     my $index = '/tmp/swish-pp';
19    
20 dpavlin 10 $i = SWISH::PlusPlus->new(
21 dpavlin 3 index_dir => $index,
22 dpavlin 9 meta_in_body => 1,
23 dpavlin 16 # debug => 1,
24 dpavlin 3 );
25     ok($i, "open index");
26 dpavlin 2
27     ok(-e $index, "index exist");
28 dpavlin 3
29 dpavlin 14 ok($i->{'cwd'}, "cwd ".$i->{'cwd'});
30    
31 dpavlin 3 ok($i->check_bin, "swish++ check");
32    
33 dpavlin 14 ok($i->{'version'}, "version ".$i->{'version'});
34 dpavlin 4
35     ok($i->index_document( 42 => 'meaning of life' ), "index 42");
36    
37 dpavlin 16 my $data = {
38 dpavlin 9 path => 'life',
39     title => 'Ultimate question answer found here',
40 dpavlin 11 body => '42 is answer to all questions',
41     meta => {
42     author => 'Dobrica Pavlinusic',
43     date => '2004-12-05',
44     comment => 'woow!',
45     },
46 dpavlin 16 };
47 dpavlin 9
48 dpavlin 16 ok($i->add( %{$data} ), "index life");
49    
50 dpavlin 4 # add one dummy document so that swish++ won't reject all words
51     # with index of just one document
52     ok($i->index_document( _dummy_ => '' ), "fillter");
53 dpavlin 7
54     cmp_ok($i->{'index_dir'}, 'eq', $index, "index_dir ok");
55 dpavlin 8
56 dpavlin 14 # I would rather test search to close it itself!
57     #$i->finish_update;
58    
59 dpavlin 8 foreach my $word (qw(meaning of life)) {
60     my @r = $i->search($word);
61     cmp_ok(scalar @r, '==', 1, "find $word");
62     }
63 dpavlin 9
64 dpavlin 16 # test_find('words to test against meta','meta')
65     sub test_find {
66     my $words = shift || die "no words?";
67     my $meta = shift;
68    
69     foreach my $word (split(/\s+/,$words)) {
70     my $path;
71     my $q = $word;
72     $q = "$meta=($word)" if ($meta);
73    
74     my @r = $i->search($q);
75     cmp_ok(scalar @r, '==', 1, "search $q");
76     if ($meta) {
77     like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property");
78     cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere");
79     }
80    
81     }
82 dpavlin 9 }
83 dpavlin 11
84 dpavlin 16 test_find($data->{'body'});
85    
86     foreach (qw(title author date comment)) {
87     test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_);
88 dpavlin 11 }
89    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26