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 #########################
7 # change 'tests => 1' to 'tests => last_test_to_print';
11 BEGIN {$SIG{__WARN__} = sub { die "Terminating test due to warning: $_[0]" } };
15 BEGIN { plan tests => 23 };
16 use Xapian qw(:standard);
17 ok(1); # If we made it this far, we're ok.
19 #########################
21 # Insert your test code below, the Test module is use()ed here so read
22 # its man page ( perldoc Test ) for help writing this test script.
24 my $doc = Xapian::Document->new();
25 my $data = "hello world";
26 $doc->set_data($data);
27 ok( $doc->get_data() eq $data );
28 $doc->add_value(1, "fudge");
29 $doc->add_value(2, "chocolate");
30 ok( $doc->get_value(1) eq "fudge" );
31 ok( $doc->get_docid() == 0 );
33 my $it = $doc->values_begin();
34 ok( $it ne $doc->values_end() );
35 ok( $it->get_value() eq "fudge" );
36 ok( $it->get_valueno() == 1 );
38 ok( $it ne $doc->values_end() );
39 ok( $it->get_value() eq "chocolate" );
40 ok( $it->get_valueno() == 2 );
42 ok( $it eq $doc->values_end() );
44 $doc->remove_value(1);
45 ok( $doc->get_value(1) eq "" );
46 ok( $doc->get_value(2) eq "chocolate" );
48 ok( $doc->get_value(2) eq "" );
50 my $database = Xapian::WritableDatabase->new();
52 # in <= 0.8.3.0 this added with wdfinc 1
53 $doc->add_posting( "hello", 1, 100 );
54 # in <= 0.8.3.0 this added with wdfinc 0
55 $doc->add_posting( "hello", 2 );
56 $database->add_document($doc);
58 ok( $database->get_doclength(1) == 101 );
60 $doc = Xapian::Document->new();
61 # in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
62 $doc->add_posting( "goodbye", 1, 1 );
63 # in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
64 $doc->add_posting( "goodbye", 2, 1 );
65 # in <= 0.8.3.0 this removed with wdfinc 0
66 $doc->remove_posting( "goodbye", 2 );
67 $database->add_document($doc);
69 ok( $database->get_doclength(2) == 1 );
71 $doc = Xapian::Document->new();
72 # in <= 0.8.3.0 this added with wdfinc 1
73 $doc->add_term( "a", 100 );
74 # in <= 0.8.3.0 this added with wdfinc 0
75 $doc->add_term( "a" );
76 $database->add_document($doc);
78 ok( $database->get_doclength(3) == 101 );
80 ok( $it = $doc->termlist_begin());
81 ok( $it ne $doc->termlist_end());
82 ok( $it->get_termname() eq "a" );
84 ok( $it eq $doc->termlist_end());
86 $doc->add_boolean_term( "b" );
87 $database->add_document($doc);
89 ok( $database->get_doclength(4) == 101 );
91 $doc->remove_term( "a" );
92 $database->add_document($doc);
94 ok( $database->get_doclength(5) == 0 );