--- trunk/t/5_Node.t 2006/01/06 01:12:10 44 +++ trunk/t/5_Node.t 2006/01/06 20:45:48 56 @@ -3,7 +3,7 @@ use strict; use blib; -use Test::More tests => 45; +use Test::More tests => 90; use Test::Exception; use Data::Dumper; @@ -51,25 +51,69 @@ #diag "draft:\n$draft"; ok(my $doc = new Search::Estraier::Document($draft), 'new doc from draft'); +ok( $node->put_doc($doc), "put_doc data001"); + for ( 1 .. 10 ) { $doc->add_attr('@uri', 'test' . $_); ok( $node->put_doc($doc), "put_doc test$_"); #diag $doc->dump_draft; } -ok( $node->out_doc( 0 ), 'out_doc'); +my $id; +ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); for ( 1 .. 5 ) { ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); } -$doc->add_attr('@uri', 'data001'); +ok($doc = $node->get_doc( $id ), 'get_doc 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->edit_doc( $doc ), "edit removed"); + +my $max = 3; + +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_order('@uri ASCD'), 'cond set_order'); +ok($cond->add_attr('@title STRINC Material'), 'cond add_attr'); + +cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query'); + +ok( my $nrec = $node->search( $cond, 0 ), 'search'); + +isa_ok( $nrec, 'Search::Estraier::NodeResult' ); + +cmp_ok($nrec->doc_num, '==', $max, "doc_num = $max"); + for ( 6 .. 10 ) { - ok( $node->get_doc( $_ ), "get_doc $_"); my $uri = 'test' . $_; + 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"); - ok( my $k = $node->etch_doc_by_uri( $uri ), "etch_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 $k = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); + ok( my $k2 = $node->etch_doc_by_uri( $uri ), "etch_doc_by_uri $uri"); + #diag Dumper($k, $k2); + ok( eq_hash( $k, $k2 ), "keywords"); } + +my $v; +ok($v = $node->name, "name: $v"); +ok($v = $node->label, "label: $v"); +ok($v = $node->doc_num, "doc_num: $v"); +ok($v = $node->word_num, "word_num: $v"); +ok($v = $node->size, "size: $v"); + +ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); + +# user doesn't exist +ok(! $node->set_user('foobar', 1), 'set_user'); + +diag "over";