3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 4; |
use Test::More tests => 12; |
7 |
use Test::Exception; |
use Test::Exception; |
8 |
#use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
10 |
BEGIN { use_ok('Search::Estraier') }; |
BEGIN { use_ok('Search::Estraier') }; |
11 |
|
|
12 |
dies_ok { new Search::Estraier::ResultDocument } "new without args"; |
my $doc = { |
|
ok(my $rdoc = new Search::Estraier::ResultDocument( |
|
13 |
uri => 'file:///foo', |
uri => 'file:///foo', |
14 |
attrs => { |
attrs => { |
15 |
foo => 1, |
foo => 1, |
17 |
}, |
}, |
18 |
snippet => 'none at all', |
snippet => 'none at all', |
19 |
keywords => "foo\tbar\tbaz\tboo", |
keywords => "foo\tbar\tbaz\tboo", |
20 |
), 'new'); |
}; |
21 |
|
|
22 |
|
dies_ok { new Search::Estraier::ResultDocument } "new without args"; |
23 |
|
ok(my $rdoc = new Search::Estraier::ResultDocument( %$doc ), 'new'); |
24 |
isa_ok($rdoc, 'Search::Estraier::ResultDocument'); |
isa_ok($rdoc, 'Search::Estraier::ResultDocument'); |
25 |
|
|
26 |
|
cmp_ok($rdoc->uri, 'eq', $doc->{uri}, 'uri'); |
27 |
|
|
28 |
|
ok(my @attr_names = keys %{ $doc->{attrs} }, "attr_names from original"); |
29 |
|
ok(my @rdoc_attr_names = $rdoc->attr_names, "attr_names from rdoc"); |
30 |
|
ok(eq_set(\@rdoc_attr_names, \@attr_names), 'attr_names comparison'); |
31 |
|
|
32 |
|
foreach my $attr (keys %{ $doc->{attrs} }) { |
33 |
|
cmp_ok($rdoc->attr($attr), 'eq', $doc->{attrs}->{$attr}, "attr: $attr"); |
34 |
|
} |
35 |
|
|
36 |
|
cmp_ok($rdoc->snippet, 'eq', $doc->{snippet}, 'snippet'); |
37 |
|
cmp_ok($rdoc->keywords, 'eq', $doc->{keywords}, 'keywords'); |