--- trunk/t/5_Node.t 2006/05/10 21:41:35 147 +++ trunk/t/5_Node.t 2006/05/15 22:06:14 148 @@ -3,13 +3,13 @@ use strict; use blib; -use Test::More tests => 142; +use Test::More tests => 246; use Test::Exception; use Data::Dumper; BEGIN { use_ok('Search::Estraier') }; -my $debug = 0; +my $debug = shift @ARGV; # name of node for test my $test1_node = '_test1_' . $$; @@ -36,8 +36,6 @@ my $msg; -ok($msg = $node->master( action => 'sync' ), "sync: $msg"); - #diag "not testing backup\n"; ok(my @users = $node->master( action => 'userlist' ), 'userlist'); @@ -123,7 +121,7 @@ # test document creation my $draft = <<'_END_OF_DRAFT_'; -@uri=data001 +@uri=data0 @title=Material Girl Living in a material world @@ -137,35 +135,45 @@ ok( $node->put_doc($doc), "put_doc data001"); -for ( 1 .. 10 ) { +for ( 1 .. 17 ) { $doc->add_attr('@uri', 'test' . $_); ok( $node->put_doc($doc), "put_doc test$_"); #diag $doc->dump_draft; } -my $id; -ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); - -my $data_max = 5; +ok(! $node->uri_to_id( 'does-not-exists' ), "non-existant uri_to_id"); -for ( 1 .. $data_max ) { - ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); -} +my $id; +ok($id = $node->uri_to_id( 'data0' ), "uri_to_id(data0)"); -ok($doc = $node->get_doc( $id ), 'get_doc for edit'); +ok($doc = $node->get_doc( $id ), "get_doc($id) for edit"); $doc->add_attr('foo', 'bar'); #diag Dumper($doc); ok( $node->edit_doc( $doc ), 'edit_doc'); -ok( $node->out_doc( $id ), "out_doc $id"); +ok( $node->out_doc( $id ), "out_doc($id)"); -ok( ! $node->edit_doc( $doc ), "edit removed"); +ok( ! $node->edit_doc( $doc ), "edit_doc of removed doc"); -my $max = 3; +my $doc_num; +ok( $doc_num = $node->doc_num, "node->doc_num $doc_num"); + +my $delete_num = 5; + +for ( 1 .. $delete_num ) { + ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); +} + +ok($msg = $node->master( action => 'sync' ), "sync: $msg"); + +my $doc_num2 = $doc_num - $delete_num; +cmp_ok($node->doc_num, '==', $doc_num2, "node->doc_num $doc_num2"); + +my $max = int($doc_num2 / 2); ok(my $cond = new Search::Estraier::Condition, 'new cond'); ok($cond->set_phrase('girl'), 'cond set_phrase'); -ok($cond->set_max($max), "cond set_max $max"); +ok($cond->set_max($max), "cond set_max($max)"); ok($cond->set_order('@uri ASCD'), 'cond set_order'); ok($cond->add_attr('@title STRINC Material'), 'cond add_attr'); @@ -175,23 +183,31 @@ isa_ok( $nres, 'Search::Estraier::NodeResult' ); -cmp_ok($nres->doc_num, '==', $max, "doc_num = $max"); +cmp_ok($nres->doc_num, '==', $max, "nres->doc_num $max"); -cmp_ok($nres->hits, '==', $data_max, "hits"); +cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2"); +# upper limit is $nres->hits and not $nres->doc_num because we +# check all documents, not just results! for my $i ( 0 .. ($nres->hits - 1) ) { - my $uri = 'test' . ($i + $data_max + 1); + my $num = $i + $delete_num + 1; + my $uri = 'test' . $num; if ($i < $nres->doc_num) { - ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i"); + ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i"); cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); + cmp_ok( $node->uri_to_id( $uri ), '==', $num + 1, "uri_to_id($uri)"); + ok( my $k = $rdoc->keywords( $id ), "rdoc keywords"); + } else { + ok( ! $nres->get_doc( $i ), "nres->get_doc doesn't exist"); + } - ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id"); - ok( $node->get_doc( $id ), "get_doc $id"); - ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); + ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri)"); + ok( $node->get_doc( $id ), "get_doc($id)"); + ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri($uri)"); cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id"); cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id"); ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); @@ -214,6 +230,26 @@ ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); +# test skip +my $skip = int($max / 2) || die "skip is zero, can't test"; +ok($cond->set_skip( $skip ), "cond set_skip($skip)"); + +ok( $nres = $node->search( $cond, 0 ), 'search'); +isa_ok( $nres, 'Search::Estraier::NodeResult' ); +cmp_ok($nres->doc_num, '==', $max, "nres->doc_num " . ($max - $skip)); +cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2"); + +for my $i ( 0 .. ($nres->doc_num - 1) ) { + my $uri = 'test' . ($i + $delete_num + 1); + ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i"); + if ($rdoc) { + cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); + } else { + fail('no rdoc'); + } +} + + # user doesn't exist ok(! $node->set_user('foobar', 1), 'set_user');