--- trunk/t/5_Node.t 2006/01/28 17:38:00 94 +++ trunk/t/5_Node.t 2006/03/12 19:43:21 117 @@ -3,7 +3,7 @@ use strict; use blib; -use Test::More tests => 98; +use Test::More tests => 115; use Test::Exception; use Data::Dumper; @@ -32,7 +32,7 @@ SKIP: { -skip "no $test1_node node in Hyper Estraier", 88, unless($node->name); +skip "no $test1_node node in Hyper Estraier", 105, unless($node->name); my @res = ( -1, 200 ); @@ -67,7 +67,9 @@ my $id; ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); -for ( 1 .. 5 ) { +my $data_max = 5; + +for ( 1 .. $data_max ) { ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); } @@ -96,17 +98,27 @@ cmp_ok($nres->doc_num, '==', $max, "doc_num = $max"); -for ( 6 .. 10 ) { - my $uri = 'test' . $_; - ok( my $id = $node->uri_to_id( $uri ), "uri_to_id $uri"); +cmp_ok($nres->hits, '==', $data_max, "hits"); + +for my $i ( 0 .. ($nres->hits - 1) ) { + my $uri = 'test' . ($i + $data_max + 1); + + if ($i < $nres->doc_num) { + ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i"); + + cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); + ok( my $k = $rdoc->keywords( $id ), "rdoc keywords"); + } + + 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"); 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 $k1 = $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"); + ok( eq_hash( $k1, $k2 ), "keywords"); } ok(my $hints = $nres->hints, 'hints'); @@ -118,7 +130,7 @@ 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(defined($v = $node->word_num), "word_num: $v"); ok($v = $node->size, "size: $v"); ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); @@ -134,13 +146,29 @@ ok($node = new Search::Estraier::Node( url => "http://localhost:1978/non-existant", croak_on_error => 1 ), "new non-existant"); throws_ok { $node->name } qr/404/, 'croak on error'; -# support for undef and 0 values -#ok($node = new Search::Estraier::Node( url => "http://localhost:1978/$test1_node", croak_on_error => 1 ), "new $test1_node"); +# croak_on_error +ok($node = new Search::Estraier::Node( url => "http://localhost:1978/node/$test1_node", croak_on_error => 1 ), "new $test1_node"); + +ok(! $node->uri_to_id('foobar'), 'uri_to_id without croak'); + +# test users + +ok(! $node->admins, 'no admins'); +ok(! $node->guests, 'no guests'); SKIP: { - skip "no $test2_node in Hyper Estraier, skipping set_link", 2 unless (my $test2_label = $node2->label); + skip "no $test2_node in Hyper Estraier, skipping set_link", 5 unless (my $test2_label = $node2->label); + + my $link_url = "http://localhost:1978/node/$test2_node"; + + ok($node->set_link( $link_url, $test2_label, 42), "set_link $test2_node ($test2_label) 42"); + + ok(my $links = $node->links, 'links'); + + cmp_ok($#{$links}, '==', 0, 'one link'); + + like($links->[0], qr/^$link_url/, 'link correct'); - ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 42), "set_link $test2_node ($test2_label) 42"); ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete"); } # SKIP 2