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