--- trunk/t/1_document.t 2006/01/04 19:28:30 12 +++ trunk/t/1_Document.t 2006/01/28 17:55:48 95 @@ -3,7 +3,7 @@ use strict; use blib; -use Test::More tests => 30; +use Test::More tests => 45; use Test::Exception; use Data::Dumper; @@ -17,6 +17,8 @@ my $attr_data = { '@uri' => 'http://localhost/Search-Estraier/', 'size' => 42, + 'zero' => 0, + 'foo' => 'bar', }; my @test_texts = ( @@ -36,8 +38,9 @@ ok($doc = new Search::Estraier::Document, 'new'); foreach my $a (keys %{$attr_data}) { - my $d = $attr_data->{$a} || die; - ok($doc->add_attr($a, $d), "add_attr $a"); + my $d = $attr_data->{$a}; + ok($doc->add_attr($a, $d), "add_attr $a = $d"); + diag "draft:\n",$doc->dump_draft,Dumper($doc->{attrs}); cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d"); } @@ -47,28 +50,27 @@ ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text'); -throws_ok { my $text = $doc->texts } qr/return array/, 'texts scalar'; -ok(my @texts = $doc->texts, 'texts array'); +ok(my @texts = $doc->texts, 'texts'); ok(my $draft = $doc->dump_draft, 'dump_draft'); -diag "dump_draft:\n$draft"; +#diag "dump_draft:\n$draft"; -#ok(my $doc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft'); -#cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same'); +ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft'); +cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same'); cmp_ok($doc->id, '==', -1, 'id'); -#cmp_ok($doc2->id, '==', -1, 'id'); +cmp_ok($doc2->id, '==', -1, 'id'); ok(my @attr = $doc->attr_names, 'attr_names'); -diag "attr_names: ", join(',',@attr), "\n"; +#diag "attr_names: ", join(',',@attr), "\n"; -cmp_ok(scalar @attr, '==', 2, 'attr_names'); +cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names'); ok(! $doc->attr('foobar'), "non-existant attr"); foreach my $a (keys %{$attr_data}) { - cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a}); + cmp_ok($doc->attr($a), 'eq', $attr_data->{$a}, "attr $a = ".$attr_data->{$a}); ok($doc->add_attr($a, undef), "delete attribute"); } @@ -76,26 +78,18 @@ #diag "attr_names left: ", join(',',$doc->attr_names), "\n"; cmp_ok(@attr, '==' , 0, "attributes removed"); -diag "texts: ", join(',',@texts), "\n"; +#diag "texts: ", join(',',@texts), "\n"; ok(eq_array(\@test_texts, \@texts), 'texts'); ok(my $cat_text = $doc->cat_texts, 'cat_text'); -diag "cat_texts: $cat_text"; +#diag "cat_texts: $cat_text"; - -SKIP: { - skip "est_keywords not implemented", 2; - - my @keywords = $doc->keywords; - diag "keywords: ", join(',',@keywords), "\n"; - - cmp_ok(scalar @keywords, '==', 1, 'keywords'); -} - - -#ok(my $snippet = $doc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet"); -#diag "make_snippet:\n$snippet"; - -#ok($doc->scan_words(qw(this is demo)), "scan_words"); +ok($doc = new Search::Estraier::Document, 'new empty'); +ok(! $doc->texts, 'texts'); +cmp_ok($doc->dump_draft, 'eq', "\n", 'dump_draft'); +cmp_ok($doc->id, '==', -1, 'id'); +ok(! $doc->attr_names, 'attr_names'); +ok(! $doc->attr(undef), 'attr'); +ok(! $doc->cat_texts, 'cat_texts'); #diag Dumper($doc);