/[Search-Estraier]/trunk/t/1_Document.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/t/1_Document.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 185 - (hide annotations)
Sun Nov 5 15:53:01 2006 UTC (17 years, 5 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3070 byte(s)
add tests for set_score and score
1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 185 use Test::More tests => 60;
7 dpavlin 9 use Test::Exception;
8 dpavlin 10 use Data::Dumper;
9 dpavlin 2
10     BEGIN { use_ok('Search::Estraier') };
11    
12 dpavlin 4 #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 dpavlin 166 my $debug = shift @ARGV;
17 dpavlin 4
18 dpavlin 2 my $attr_data = {
19     '@uri' => 'http://localhost/Search-Estraier/',
20     'size' => 42,
21 dpavlin 95 'zero' => 0,
22     'foo' => 'bar',
23 dpavlin 97 'empty' => '',
24 dpavlin 2 };
25    
26 dpavlin 10 my @test_texts = (
27     'This is a test',
28     'of pure-perl bindings',
29     'for HyperEstraier'
30     );
31    
32 dpavlin 166 my $vectors = {
33     'foo' => 42,
34     'bar' => 100,
35     'baz' => 0,
36     };
37    
38 dpavlin 6 ok(my $doc = new Search::Estraier::Document, 'new');
39 dpavlin 2
40 dpavlin 9 isa_ok($doc, 'Search::Estraier::Document');
41    
42 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
43 dpavlin 2
44 dpavlin 6 ok($doc->delete, "delete");
45 dpavlin 2
46 dpavlin 6 ok($doc = new Search::Estraier::Document, 'new');
47    
48 dpavlin 2 foreach my $a (keys %{$attr_data}) {
49 dpavlin 95 my $d = $attr_data->{$a};
50     ok($doc->add_attr($a, $d), "add_attr $a = $d");
51 dpavlin 99 #diag "draft:\n",$doc->dump_draft,Dumper($doc->{attrs});
52 dpavlin 8 cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d");
53 dpavlin 2 }
54    
55 dpavlin 10 foreach my $t (@test_texts) {
56     ok($doc->add_text($t), "add_text: $t");
57     }
58    
59 dpavlin 6 ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
60 dpavlin 2
61 dpavlin 166 ok($doc->add_vectors( %{ $vectors } ), 'add_vectors');
62    
63     diag "current doc: ", Dumper($doc) if ($debug);
64    
65 dpavlin 60 ok(my @texts = $doc->texts, 'texts');
66 dpavlin 9
67 dpavlin 6 ok(my $draft = $doc->dump_draft, 'dump_draft');
68 dpavlin 2
69 dpavlin 97 foreach my $a (keys %{$attr_data}) {
70     my $regex = $a . '=' . $attr_data->{$a};
71     like($draft, qr/$regex/, "draft has $regex");
72     }
73    
74 dpavlin 166 diag "dump_draft:\n$draft" if ($debug);
75 dpavlin 2
76 dpavlin 14 ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');
77 dpavlin 166 diag "doc from draft: ", Dumper($doc2) if ($debug);
78 dpavlin 14 cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
79 dpavlin 2
80 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
81 dpavlin 14 cmp_ok($doc2->id, '==', -1, 'id');
82 dpavlin 2
83 dpavlin 9 ok(my @attr = $doc->attr_names, 'attr_names');
84 dpavlin 166 diag "attr_names: ", join(',',@attr), "\n" if ($debug);
85 dpavlin 2
86 dpavlin 95 cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names');
87 dpavlin 2
88 dpavlin 6 ok(! $doc->attr('foobar'), "non-existant attr");
89 dpavlin 2
90     foreach my $a (keys %{$attr_data}) {
91 dpavlin 95 cmp_ok($doc->attr($a), 'eq', $attr_data->{$a}, "attr $a = ".$attr_data->{$a});
92 dpavlin 9 ok($doc->add_attr($a, undef), "delete attribute");
93 dpavlin 2 }
94    
95 dpavlin 10 @attr = $doc->attr_names;
96 dpavlin 166 diag "attr_names left: ", join(',',$doc->attr_names), "\n" if ($debug);
97 dpavlin 9 cmp_ok(@attr, '==' , 0, "attributes removed");
98 dpavlin 2
99 dpavlin 166 diag "texts: ", join(',',@texts), "\n" if ($debug);
100 dpavlin 10 ok(eq_array(\@test_texts, \@texts), 'texts');
101 dpavlin 2
102 dpavlin 12 ok(my $cat_text = $doc->cat_texts, 'cat_text');
103 dpavlin 166 diag "cat_texts: $cat_text" if ($debug);
104 dpavlin 12
105 dpavlin 60 ok($doc = new Search::Estraier::Document, 'new empty');
106     ok(! $doc->texts, 'texts');
107     cmp_ok($doc->dump_draft, 'eq', "\n", 'dump_draft');
108     cmp_ok($doc->id, '==', -1, 'id');
109     ok(! $doc->attr_names, 'attr_names');
110     ok(! $doc->attr(undef), 'attr');
111     ok(! $doc->cat_texts, 'cat_texts');
112    
113 dpavlin 185 ok($doc = new Search::Estraier::Document, 'new empty');
114     cmp_ok($doc->score, '==', -1, 'no score');
115     ok($doc->set_score(12345), 'set_score');
116     cmp_ok($doc->score, '==', 12345, 'score');
117     like($doc->dump_draft, qr/%SCORE\s+12345/, 'dump_draft has %SCORE');
118    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26