/[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

Contents of /trunk/t/01swish.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show 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 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 47;
6 use Test::Exception;
7 use blib;
8
9 BEGIN {
10 use_ok('SWISH::PlusPlus')
11 };
12
13 my $i;
14
15 throws_ok { SWISH::PlusPlus->new() } qr/index_dir/, "need index_dir";
16
17 ## FIXME
18 my $index = '/tmp/swish-pp';
19
20 $i = SWISH::PlusPlus->new(
21 index_dir => $index,
22 meta_in_body => 1,
23 # debug => 1,
24 );
25 ok($i, "open index");
26
27 ok(-e $index, "index exist");
28
29 ok($i->{'cwd'}, "cwd ".$i->{'cwd'});
30
31 ok($i->check_bin, "swish++ check");
32
33 ok($i->{'version'}, "version ".$i->{'version'});
34
35 ok($i->index_document( 42 => 'meaning of life' ), "index 42");
36
37 my $data = {
38 path => 'life',
39 title => 'Ultimate question answer found here',
40 body => '42 is answer to all questions',
41 meta => {
42 author => 'Dobrica Pavlinusic',
43 date => '2004-12-05',
44 comment => 'woow!',
45 },
46 };
47
48 ok($i->add( %{$data} ), "index life");
49
50 # 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
54 cmp_ok($i->{'index_dir'}, 'eq', $index, "index_dir ok");
55
56 # I would rather test search to close it itself!
57 #$i->finish_update;
58
59 foreach my $word (qw(meaning of life)) {
60 my @r = $i->search($word);
61 cmp_ok(scalar @r, '==', 1, "find $word");
62 }
63
64 # 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 }
83
84 test_find($data->{'body'});
85
86 foreach (qw(title author date comment)) {
87 test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_);
88 }
89

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26