--- trunk/t/1_document.t 2006/01/04 13:11:43 2 +++ trunk/t/1_Document.t 2006/01/07 00:00:15 60 @@ -3,69 +3,90 @@ use strict; use blib; -use Test::More tests => 25; +use Test::More tests => 37; +use Test::Exception; +use Data::Dumper; BEGIN { use_ok('Search::Estraier') }; +#print Search::Estraier::Document::_s('foo'); + +#cmp_ok(Search::Estraier::Document::_s(" this is a text "), 'eq', 'this is a text', '_s - strip spaces'); + + my $attr_data = { '@uri' => 'http://localhost/Search-Estraier/', 'size' => 42, }; -ok(my $estdoc = new Search::Estraier::Document, 'new'); - -ok($estdoc->delete, "delete"); +my @test_texts = ( + 'This is a test', + 'of pure-perl bindings', + 'for HyperEstraier' +); -ok($estdoc = new Search::Estraier::Document, 'new'); +ok(my $doc = new Search::Estraier::Document, 'new'); -foreach my $a (keys %{$attr_data}) { - ok($estdoc->add_attr($a, $attr_data->{$a}), "add_attr $a"); -} +isa_ok($doc, 'Search::Estraier::Document'); -ok($estdoc->add_text('This is a demo'), 'add_text'); -ok($estdoc->add_hidden_text('This is hidden text'), 'add_hidden_text'); +cmp_ok($doc->id, '==', -1, 'id'); -ok(my $draft = $estdoc->dump_draft, 'dump_draft'); +ok($doc->delete, "delete"); -diag "dump_draft:\n$draft"; +ok($doc = new Search::Estraier::Document, 'new'); -ok(my $estdoc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft'); -cmp_ok($estdoc2->dump_draft, 'eq', $draft, 'drafts same'); +foreach my $a (keys %{$attr_data}) { + my $d = $attr_data->{$a} || die; + ok($doc->add_attr($a, $d), "add_attr $a"); + cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d"); +} -cmp_ok($estdoc->id, '==', -1, 'id'); -cmp_ok($estdoc2->id, '==', -1, 'id'); +foreach my $t (@test_texts) { + ok($doc->add_text($t), "add_text: $t"); +} -my @attr = $estdoc->attr_names; -diag "attr_names: ", join(',',@attr), "\n"; +ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text'); -cmp_ok(scalar @attr, '==', 2, 'attr_names'); +ok(my @texts = $doc->texts, 'texts'); -ok(! $estdoc->attr('foobar'), "non-existant attr"); +ok(my $draft = $doc->dump_draft, 'dump_draft'); -foreach my $a (keys %{$attr_data}) { - cmp_ok($attr_data->{$a}, 'eq', $estdoc->attr($a), "attr $a = ".$attr_data->{$a}); - ok($estdoc->add_attr($a, ''), "delete attribute"); -} +#diag "dump_draft:\n$draft"; -#diag "attr_names left: ", join(',',$estdoc->attr_names), "\n"; -cmp_ok($estdoc->attr_names, '==' , 0, "attributes removed"); +ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft'); +cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same'); -my @texts = $estdoc->texts; -diag "texts: ", join(',',@texts), "\n"; +cmp_ok($doc->id, '==', -1, 'id'); +cmp_ok($doc2->id, '==', -1, 'id'); -cmp_ok(scalar @texts, '==', 1, 'texts'); +ok(my @attr = $doc->attr_names, 'attr_names'); +#diag "attr_names: ", join(',',@attr), "\n"; -SKIP: { - skip "est_keywords not implemented", 2; +cmp_ok(scalar @attr, '==', 2, 'attr_names'); - my @keywords = $estdoc->keywords; - diag "keywords: ", join(',',@keywords), "\n"; +ok(! $doc->attr('foobar'), "non-existant attr"); - cmp_ok(scalar @keywords, '==', 1, 'keywords'); +foreach my $a (keys %{$attr_data}) { + cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a}); + ok($doc->add_attr($a, undef), "delete attribute"); } +@attr = $doc->attr_names; +#diag "attr_names left: ", join(',',$doc->attr_names), "\n"; +cmp_ok(@attr, '==' , 0, "attributes removed"); + +#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"; + +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'); -ok(my $snippet = $estdoc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet"); -diag "make_snippet:\n$snippet"; - -ok($estdoc->scan_words(qw(this is demo)), "scan_words"); +#diag Dumper($doc);