3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 37; |
use Test::More tests => 45; |
7 |
use Test::Exception; |
use Test::Exception; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
17 |
my $attr_data = { |
my $attr_data = { |
18 |
'@uri' => 'http://localhost/Search-Estraier/', |
'@uri' => 'http://localhost/Search-Estraier/', |
19 |
'size' => 42, |
'size' => 42, |
20 |
|
'zero' => 0, |
21 |
|
'foo' => 'bar', |
22 |
}; |
}; |
23 |
|
|
24 |
my @test_texts = ( |
my @test_texts = ( |
38 |
ok($doc = new Search::Estraier::Document, 'new'); |
ok($doc = new Search::Estraier::Document, 'new'); |
39 |
|
|
40 |
foreach my $a (keys %{$attr_data}) { |
foreach my $a (keys %{$attr_data}) { |
41 |
my $d = $attr_data->{$a} || die; |
my $d = $attr_data->{$a}; |
42 |
ok($doc->add_attr($a, $d), "add_attr $a"); |
ok($doc->add_attr($a, $d), "add_attr $a = $d"); |
43 |
|
diag "draft:\n",$doc->dump_draft,Dumper($doc->{attrs}); |
44 |
cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d"); |
cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d"); |
45 |
} |
} |
46 |
|
|
65 |
ok(my @attr = $doc->attr_names, 'attr_names'); |
ok(my @attr = $doc->attr_names, 'attr_names'); |
66 |
#diag "attr_names: ", join(',',@attr), "\n"; |
#diag "attr_names: ", join(',',@attr), "\n"; |
67 |
|
|
68 |
cmp_ok(scalar @attr, '==', 2, 'attr_names'); |
cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names'); |
69 |
|
|
70 |
ok(! $doc->attr('foobar'), "non-existant attr"); |
ok(! $doc->attr('foobar'), "non-existant attr"); |
71 |
|
|
72 |
foreach my $a (keys %{$attr_data}) { |
foreach my $a (keys %{$attr_data}) { |
73 |
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}); |
74 |
ok($doc->add_attr($a, undef), "delete attribute"); |
ok($doc->add_attr($a, undef), "delete attribute"); |
75 |
} |
} |
76 |
|
|