1use strict;
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'
4
5#########################
6
7# change 'tests => 1' to 'tests => last_test_to_print';
8
9use Test;
10use Devel::Peek;
11BEGIN { plan tests => 26 };
12use Search::Xapian qw(:standard);
13ok(1); # If we made it this far, we're ok.
14
15#########################
16
17# Insert your test code below, the Test module is use()ed here so read
18# its man page ( perldoc Test ) for help writing this test script.
19
20my $doc = Search::Xapian::Document->new();
21my $data = "hello world";
22$doc->set_data($data);
23ok( $doc->get_data() eq $data );
24$doc->add_value(1, "fudge");
25$doc->add_value(2, "chocolate");
26ok( $doc->get_value(1) eq "fudge" );
27ok( $doc->get_docid() == 0 );
28
29my $it = $doc->values_begin();
30ok( $it ne $doc->values_end() );
31ok( "$it" eq "fudge" );
32ok( $it->get_value() eq "fudge" );
33ok( $it->get_valueno() == 1 );
34++$it;
35ok( $it ne $doc->values_end() );
36ok( "$it" eq "chocolate" );
37ok( $it->get_value() eq "chocolate" );
38ok( $it->get_valueno() == 2 );
39++$it;
40ok( $it eq $doc->values_end() );
41
42$doc->remove_value(1);
43ok( $doc->get_value(1) eq "" );
44ok( $doc->get_value(2) eq "chocolate" );
45$doc->clear_values();
46ok( $doc->get_value(2) eq "" );
47
48my $database = Search::Xapian::WritableDatabase->new();
49
50# in <= 0.8.3.0 this added with wdfinc 1
51$doc->add_posting( "hello", 1, 100 );
52# in <= 0.8.3.0 this added with wdfinc 0
53$doc->add_posting( "hello", 2 );
54$database->add_document($doc);
55
56ok( $database->get_doclength(1) == 101 );
57
58$doc = Search::Xapian::Document->new();
59# in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
60$doc->add_posting( "goodbye", 1, 1 );
61# in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
62$doc->add_posting( "goodbye", 2, 1 );
63# in <= 0.8.3.0 this removed with wdfinc 0
64$doc->remove_posting( "goodbye", 2 );
65$database->add_document($doc);
66
67ok( $database->get_doclength(2) == 1 );
68
69$doc = Search::Xapian::Document->new();
70# in <= 0.8.3.0 this added with wdfinc 1
71$doc->add_term( "a", 100 );
72# in <= 0.8.3.0 this added with wdfinc 0
73$doc->add_term( "a" );
74$database->add_document($doc);
75
76ok( $database->get_doclength(3) == 101 );
77
78ok( $it = $doc->termlist_begin());
79ok( $it ne $doc->termlist_end());
80ok( "$it" eq "a" );
81ok( $it->get_termname() eq "a" );
82++$it;
83ok( $it eq $doc->termlist_end());
84
85$doc->add_boolean_term( "b" );
86$database->add_document($doc);
87
88ok( $database->get_doclength(4) == 101 );
89
90$doc->remove_term( "a" );
91$database->add_document($doc);
92
93ok( $database->get_doclength(5) == 0 );
94
951;
96