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

Diff of /trunk/t/01swish.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/t/swish.t revision 14 by dpavlin, Sun Dec 5 15:35:53 2004 UTC trunk/t/01swish.t revision 22 by dpavlin, Tue Dec 7 16:05:43 2004 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 29;  use Test::More tests => 56;
6  use Test::Exception;  use Test::Exception;
 use lib '.';  
7  use blib;  use blib;
8    
9  BEGIN {  BEGIN {
# Line 17  throws_ok { SWISH::PlusPlus->new() } qr/ Line 16  throws_ok { SWISH::PlusPlus->new() } qr/
16    
17  ## FIXME  ## FIXME
18  my $index = '/tmp/swish-pp';  my $index = '/tmp/swish-pp';
19    my $debug = 0;
20    $debug = 4 if (@ARGV);
21    
22  $i = SWISH::PlusPlus->new(  $i = SWISH::PlusPlus->new(
23          index_dir => $index,          index_dir => $index,
         debug => 0,  
24          meta_in_body => 1,          meta_in_body => 1,
25            debug => $debug,
26  );  );
27  ok($i, "open index");  ok($i, "open index");
28    
# Line 35  ok($i->{'version'}, "version ".$i->{'ver Line 36  ok($i->{'version'}, "version ".$i->{'ver
36    
37  ok($i->index_document( 42 => 'meaning of life' ), "index 42");  ok($i->index_document( 42 => 'meaning of life' ), "index 42");
38    
39  ok($i->add(  my $data = {
40          path => 'life',          path => 'life',
41          title => 'Ultimate question answer found here',          title => 'Ultimate question answer found here',
42          body => '42 is answer to all questions',          body => '42 is answer to all questions',
# Line 44  ok($i->add( Line 45  ok($i->add(
45                  date => '2004-12-05',                  date => '2004-12-05',
46                  comment => 'woow!',                  comment => 'woow!',
47          },          },
48  ), "index life");  };
49    
50    ok($i->add( %{$data} ), "index life");
51    
52  # add one dummy document so that swish++ won't reject all words  # add one dummy document so that swish++ won't reject all words
53  # with index of just one document  # with index of just one document
# Line 60  foreach my $word (qw(meaning of life)) { Line 63  foreach my $word (qw(meaning of life)) {
63          cmp_ok(scalar @r, '==', 1, "find $word");          cmp_ok(scalar @r, '==', 1, "find $word");
64  }  }
65    
66  foreach my $word (qw(Ultimate question answer found here)) {  # test_find('words to test against meta','meta', nr_results)
67          cmp_ok(scalar $i->search("title=($word)"), '==', 1, "find $word in title");  sub test_find {
68          cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere");          my $words = shift || die "no words?";
69            my $meta = shift;
70            my $nr = shift;
71    
72            $nr = 1 unless defined($nr);
73    
74            foreach my $word (split(/\s+/,$words)) {
75                    my $path;
76                    my $q = $word;
77                    $q = "$meta=($word)" if ($meta);
78                    
79                    my @r = $i->search($q);
80                    cmp_ok(scalar @r, '==', $nr, "search $q - $nr results");
81                    if ($meta) {
82                            like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property");
83                            cmp_ok(scalar $i->search("$word"), '==', $nr, "find $word anywhere -- $nr results");
84                    }
85                    
86            }
87  }  }
88    
89  foreach my $word (qw(Dobrica Pavlinusic)) {  test_find($data->{'body'});
90          cmp_ok(scalar $i->search("author=($word)"), '==', 1, "find $word in author");  
91    foreach (qw(title author date comment)) {
92            test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_);
93  }  }
94    
95  cmp_ok(scalar $i->search("date=2004-12-05"), '==', 1, "found date");  ok($i->delete("life"), "delete life");
96    ok($i->{'_deleted'}->{'life'}, "life marked as deleted");
97    
98    ok($i->finish_update, "finish_update");
99    
100  cmp_ok(scalar $i->search("woow!"), '==', 1, "found woow");  test_find($data->{'body'}, undef, '0');
 cmp_ok(scalar $i->search("comment=(woow)"), '==', 1, "found woow");  

Legend:
Removed from v.14  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26