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