1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use strict; |
4 |
use blib; |
5 |
|
6 |
use Test::More tests => 25; |
7 |
|
8 |
BEGIN { use_ok('Search::Estraier') }; |
9 |
|
10 |
#print Search::Estraier::Document::_s('foo'); |
11 |
|
12 |
#cmp_ok(Search::Estraier::Document::_s(" this is a text "), 'eq', 'this is a text', '_s - strip spaces'); |
13 |
|
14 |
|
15 |
my $attr_data = { |
16 |
'@uri' => 'http://localhost/Search-Estraier/', |
17 |
'size' => 42, |
18 |
}; |
19 |
|
20 |
ok(my $estdoc = new Search::Estraier::Document, 'new'); |
21 |
|
22 |
ok($estdoc->delete, "delete"); |
23 |
|
24 |
ok($estdoc = new Search::Estraier::Document, 'new'); |
25 |
|
26 |
foreach my $a (keys %{$attr_data}) { |
27 |
ok($estdoc->add_attr($a, $attr_data->{$a}), "add_attr $a"); |
28 |
} |
29 |
|
30 |
ok($estdoc->add_text('This is a demo'), 'add_text'); |
31 |
ok($estdoc->add_hidden_text('This is hidden text'), 'add_hidden_text'); |
32 |
|
33 |
ok(my $draft = $estdoc->dump_draft, 'dump_draft'); |
34 |
|
35 |
diag "dump_draft:\n$draft"; |
36 |
|
37 |
ok(my $estdoc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft'); |
38 |
cmp_ok($estdoc2->dump_draft, 'eq', $draft, 'drafts same'); |
39 |
|
40 |
cmp_ok($estdoc->id, '==', -1, 'id'); |
41 |
cmp_ok($estdoc2->id, '==', -1, 'id'); |
42 |
|
43 |
my @attr = $estdoc->attr_names; |
44 |
diag "attr_names: ", join(',',@attr), "\n"; |
45 |
|
46 |
cmp_ok(scalar @attr, '==', 2, 'attr_names'); |
47 |
|
48 |
ok(! $estdoc->attr('foobar'), "non-existant attr"); |
49 |
|
50 |
foreach my $a (keys %{$attr_data}) { |
51 |
cmp_ok($attr_data->{$a}, 'eq', $estdoc->attr($a), "attr $a = ".$attr_data->{$a}); |
52 |
ok($estdoc->add_attr($a, ''), "delete attribute"); |
53 |
} |
54 |
|
55 |
#diag "attr_names left: ", join(',',$estdoc->attr_names), "\n"; |
56 |
cmp_ok($estdoc->attr_names, '==' , 0, "attributes removed"); |
57 |
|
58 |
my @texts = $estdoc->texts; |
59 |
diag "texts: ", join(',',@texts), "\n"; |
60 |
|
61 |
cmp_ok(scalar @texts, '==', 1, 'texts'); |
62 |
|
63 |
SKIP: { |
64 |
skip "est_keywords not implemented", 2; |
65 |
|
66 |
my @keywords = $estdoc->keywords; |
67 |
diag "keywords: ", join(',',@keywords), "\n"; |
68 |
|
69 |
cmp_ok(scalar @keywords, '==', 1, 'keywords'); |
70 |
} |
71 |
|
72 |
|
73 |
ok(my $snippet = $estdoc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet"); |
74 |
diag "make_snippet:\n$snippet"; |
75 |
|
76 |
ok($estdoc->scan_words(qw(this is demo)), "scan_words"); |