2 # Before 'make install' is performed this script should be runnable with
3 # 'make test'. After 'make install' it should work as 'perl test.pl'
5 #########################
9 BEGIN {$SIG{__WARN__} = sub { die "Terminating test due to warning: $_[0]" } };
13 BEGIN { plan tests => 28 };
14 use Xapian qw(:standard);
15 ok(1); # If we made it this far, we're ok.
17 #########################
19 # Insert your test code below, the Test module is use()ed here so read
20 # its man page ( perldoc Test ) for help writing this test script.
22 # first create database dir, if it doesn't exist;
24 my $termgen = new Xapian::TermGenerator();
25 my $doc = new Xapian::Document();
26 $termgen->set_document($doc);
27 $termgen->index_text('foo bar baz foo');
28 $termgen->index_text_without_positions('baz zoo');
30 my $ti = $doc->termlist_begin();
31 ok( $ti ne $doc->termlist_end());
32 ok( $ti->get_termname(), 'bar' );
33 ok( $ti->get_wdf(), 1 );
34 my $pi = $ti->positionlist_begin();
35 ok( $pi ne $ti->positionlist_end() );
36 ok( $pi->get_termpos(), 2 );
37 ok( ++$pi, $ti->positionlist_end() );
39 ok( ++$ti ne $doc->termlist_end());
40 ok( $ti->get_termname(), 'baz' );
41 ok( $ti->get_wdf(), 2 );
42 $pi = $ti->positionlist_begin();
43 ok( $pi ne $ti->positionlist_end() );
44 ok( $pi->get_termpos(), 3 );
45 ok( ++$pi, $ti->positionlist_end() );
47 ok( ++$ti ne $doc->termlist_end() );
48 ok( $ti->get_termname(), 'foo' );
49 ok( $ti->get_wdf(), 2 );
50 $pi = $ti->positionlist_begin();
51 ok( $pi ne $ti->positionlist_end() );
52 ok( $pi->get_termpos(), 1 );
53 ok( ++$pi ne $ti->positionlist_end() );
54 ok( $pi->get_termpos(), 4 );
55 ok( ++$pi, $ti->positionlist_end() );
57 ok( ++$ti ne $doc->termlist_end() );
58 ok( $ti->get_termname(), 'zoo' );
59 ok( $ti->get_wdf(), 1 );
60 $pi = $ti->positionlist_begin();
61 ok( $pi, $ti->positionlist_end() );
63 ok( ++$ti eq $doc->termlist_end() );
65 my $db = Xapian::WritableDatabase->new("testdb-spell", DB_CREATE_OR_OVERWRITE);
67 my $indexer = Xapian::TermGenerator->new();
68 $indexer->set_flags(Xapian::FLAG_SPELLING);
69 $indexer->set_database($db);
70 my $document = Xapian::Document->new();
71 $indexer->set_document($document);
72 $indexer->index_text('test hello');
73 $termgen->index_text('foo bar baz foo', 4);
74 $termgen->index_text_without_positions('baz zoo', 42);
75 ok( $db->add_document($document) );