--- trunk/t/3_ResultDocument.t 2006/01/05 13:55:55 22 +++ trunk/t/3_ResultDocument.t 2006/01/05 14:30:42 23 @@ -3,14 +3,13 @@ use strict; use blib; -use Test::More tests => 4; +use Test::More tests => 12; use Test::Exception; -#use Data::Dumper; +use Data::Dumper; BEGIN { use_ok('Search::Estraier') }; -dies_ok { new Search::Estraier::ResultDocument } "new without args"; -ok(my $rdoc = new Search::Estraier::ResultDocument( +my $doc = { uri => 'file:///foo', attrs => { foo => 1, @@ -18,6 +17,21 @@ }, snippet => 'none at all', keywords => "foo\tbar\tbaz\tboo", -), 'new'); +}; + +dies_ok { new Search::Estraier::ResultDocument } "new without args"; +ok(my $rdoc = new Search::Estraier::ResultDocument( %$doc ), 'new'); isa_ok($rdoc, 'Search::Estraier::ResultDocument'); +cmp_ok($rdoc->uri, 'eq', $doc->{uri}, 'uri'); + +ok(my @attr_names = keys %{ $doc->{attrs} }, "attr_names from original"); +ok(my @rdoc_attr_names = $rdoc->attr_names, "attr_names from rdoc"); +ok(eq_set(\@rdoc_attr_names, \@attr_names), 'attr_names comparison'); + +foreach my $attr (keys %{ $doc->{attrs} }) { + cmp_ok($rdoc->attr($attr), 'eq', $doc->{attrs}->{$attr}, "attr: $attr"); +} + +cmp_ok($rdoc->snippet, 'eq', $doc->{snippet}, 'snippet'); +cmp_ok($rdoc->keywords, 'eq', $doc->{keywords}, 'keywords');