3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 25; |
use Test::More tests => 30; |
7 |
|
use Test::Exception; |
8 |
|
use Data::Dumper; |
9 |
|
|
10 |
BEGIN { use_ok('Search::Estraier') }; |
BEGIN { use_ok('Search::Estraier') }; |
11 |
|
|
19 |
'size' => 42, |
'size' => 42, |
20 |
}; |
}; |
21 |
|
|
22 |
ok(my $estdoc = new Search::Estraier::Document, 'new'); |
my @test_texts = ( |
23 |
|
'This is a test', |
24 |
|
'of pure-perl bindings', |
25 |
|
'for HyperEstraier' |
26 |
|
); |
27 |
|
|
28 |
ok($estdoc->delete, "delete"); |
ok(my $doc = new Search::Estraier::Document, 'new'); |
29 |
|
|
30 |
ok($estdoc = new Search::Estraier::Document, 'new'); |
isa_ok($doc, 'Search::Estraier::Document'); |
31 |
|
|
32 |
|
cmp_ok($doc->id, '==', -1, 'id'); |
33 |
|
|
34 |
|
ok($doc->delete, "delete"); |
35 |
|
|
36 |
|
ok($doc = new Search::Estraier::Document, 'new'); |
37 |
|
|
38 |
foreach my $a (keys %{$attr_data}) { |
foreach my $a (keys %{$attr_data}) { |
39 |
ok($estdoc->add_attr($a, $attr_data->{$a}), "add_attr $a"); |
my $d = $attr_data->{$a} || die; |
40 |
|
ok($doc->add_attr($a, $d), "add_attr $a"); |
41 |
|
cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d"); |
42 |
|
} |
43 |
|
|
44 |
|
foreach my $t (@test_texts) { |
45 |
|
ok($doc->add_text($t), "add_text: $t"); |
46 |
} |
} |
47 |
|
|
48 |
ok($estdoc->add_text('This is a demo'), 'add_text'); |
ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text'); |
49 |
ok($estdoc->add_hidden_text('This is hidden text'), 'add_hidden_text'); |
|
50 |
|
throws_ok { my $text = $doc->texts } qr/return array/, 'texts scalar'; |
51 |
|
ok(my @texts = $doc->texts, 'texts array'); |
52 |
|
|
53 |
ok(my $draft = $estdoc->dump_draft, 'dump_draft'); |
ok(my $draft = $doc->dump_draft, 'dump_draft'); |
54 |
|
|
55 |
diag "dump_draft:\n$draft"; |
diag "dump_draft:\n$draft"; |
56 |
|
|
57 |
ok(my $estdoc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft'); |
#ok(my $doc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft'); |
58 |
cmp_ok($estdoc2->dump_draft, 'eq', $draft, 'drafts same'); |
#cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same'); |
59 |
|
|
60 |
cmp_ok($estdoc->id, '==', -1, 'id'); |
cmp_ok($doc->id, '==', -1, 'id'); |
61 |
cmp_ok($estdoc2->id, '==', -1, 'id'); |
#cmp_ok($doc2->id, '==', -1, 'id'); |
62 |
|
|
63 |
my @attr = $estdoc->attr_names; |
ok(my @attr = $doc->attr_names, 'attr_names'); |
64 |
diag "attr_names: ", join(',',@attr), "\n"; |
diag "attr_names: ", join(',',@attr), "\n"; |
65 |
|
|
66 |
cmp_ok(scalar @attr, '==', 2, 'attr_names'); |
cmp_ok(scalar @attr, '==', 2, 'attr_names'); |
67 |
|
|
68 |
ok(! $estdoc->attr('foobar'), "non-existant attr"); |
ok(! $doc->attr('foobar'), "non-existant attr"); |
69 |
|
|
70 |
foreach my $a (keys %{$attr_data}) { |
foreach my $a (keys %{$attr_data}) { |
71 |
cmp_ok($attr_data->{$a}, 'eq', $estdoc->attr($a), "attr $a = ".$attr_data->{$a}); |
cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a}); |
72 |
ok($estdoc->add_attr($a, ''), "delete attribute"); |
ok($doc->add_attr($a, undef), "delete attribute"); |
73 |
} |
} |
74 |
|
|
75 |
#diag "attr_names left: ", join(',',$estdoc->attr_names), "\n"; |
@attr = $doc->attr_names; |
76 |
cmp_ok($estdoc->attr_names, '==' , 0, "attributes removed"); |
#diag "attr_names left: ", join(',',$doc->attr_names), "\n"; |
77 |
|
cmp_ok(@attr, '==' , 0, "attributes removed"); |
78 |
|
|
|
my @texts = $estdoc->texts; |
|
79 |
diag "texts: ", join(',',@texts), "\n"; |
diag "texts: ", join(',',@texts), "\n"; |
80 |
|
ok(eq_array(\@test_texts, \@texts), 'texts'); |
81 |
|
|
82 |
|
ok(my $cat_text = $doc->cat_texts, 'cat_text'); |
83 |
|
diag "cat_texts: $cat_text"; |
84 |
|
|
|
cmp_ok(scalar @texts, '==', 1, 'texts'); |
|
85 |
|
|
86 |
SKIP: { |
SKIP: { |
87 |
skip "est_keywords not implemented", 2; |
skip "est_keywords not implemented", 2; |
88 |
|
|
89 |
my @keywords = $estdoc->keywords; |
my @keywords = $doc->keywords; |
90 |
diag "keywords: ", join(',',@keywords), "\n"; |
diag "keywords: ", join(',',@keywords), "\n"; |
91 |
|
|
92 |
cmp_ok(scalar @keywords, '==', 1, 'keywords'); |
cmp_ok(scalar @keywords, '==', 1, 'keywords'); |
93 |
} |
} |
94 |
|
|
95 |
|
|
96 |
ok(my $snippet = $estdoc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet"); |
#ok(my $snippet = $doc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet"); |
97 |
diag "make_snippet:\n$snippet"; |
#diag "make_snippet:\n$snippet"; |
98 |
|
|
99 |
|
#ok($doc->scan_words(qw(this is demo)), "scan_words"); |
100 |
|
|
101 |
ok($estdoc->scan_words(qw(this is demo)), "scan_words"); |
#diag Dumper($doc); |