1# Before `make install' is performed this script should be runnable with 2# `make test'. After `make install' it should work as `perl test.pl' 3 4######################### 5 6# change 'tests => 1' to 'tests => last_test_to_print'; 7 8use Test; 9use Devel::Peek; 10BEGIN { plan tests => 26 }; 11use Search::Xapian qw(:standard); 12ok(1); # If we made it this far, we're ok. 13 14# FIXME: these tests pass in the XS version. 15my $disable_fixme = 1; 16 17######################### 18 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. 21 22my $doc = Search::Xapian::Document->new(); 23$data = "hello world"; 24$doc->set_data($data); 25ok( $doc->get_data() eq $data ); 26$doc->add_value(1, "fudge"); 27$doc->add_value(2, "chocolate"); 28ok( $doc->get_value(1) eq "fudge" ); 29ok( $doc->get_docid() == 0 ); 30 31my $it = $doc->values_begin(); 32ok( $it ne $doc->values_end() ); 33ok( $disable_fixme || "$it" eq "fudge" ); 34ok( $it->get_value() eq "fudge" ); 35ok( $it->get_valueno() == 1 ); 36++$it; 37ok( $it ne $doc->values_end() ); 38ok( $disable_fixme || "$it" eq "chocolate" ); 39ok( $it->get_value() eq "chocolate" ); 40ok( $it->get_valueno() == 2 ); 41++$it; 42ok( $it eq $doc->values_end() ); 43 44$doc->remove_value(1); 45ok( $doc->get_value(1) eq "" ); 46ok( $doc->get_value(2) eq "chocolate" ); 47$doc->clear_values(); 48ok( $doc->get_value(2) eq "" ); 49 50my $database = Search::Xapian::WritableDatabase->new(); 51 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); 57 58ok( $database->get_doclength(1) == 101 ); 59 60$doc = Search::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); 68 69ok( $database->get_doclength(2) == 1 ); 70 71$doc = Search::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); 77 78ok( $database->get_doclength(3) == 101 ); 79 80ok( $it = $doc->termlist_begin()); 81ok( $it ne $doc->termlist_end()); 82ok( $disable_fixme || "$it" eq "a" ); 83ok( $it->get_termname() eq "a" ); 84++$it; 85ok( $it eq $doc->termlist_end()); 86 87$doc->add_boolean_term( "b" ); 88$database->add_document($doc); 89 90ok( $database->get_doclength(4) == 101 ); 91 92$doc->remove_term( "a" ); 93$database->add_document($doc); 94 95ok( $database->get_doclength(5) == 0 ); 96 971; 98