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