/[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 10 - (hide annotations)
Wed Jan 4 15:48:00 2006 UTC (18 years, 3 months ago) by dpavlin
Original Path: trunk/t/1_document.t
File MIME type: application/x-troff
File size: 2409 byte(s)
demonstrate bug with texts
1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 10 use Test::More tests => 28;
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    
17 dpavlin 2 my $attr_data = {
18     '@uri' => 'http://localhost/Search-Estraier/',
19     'size' => 42,
20     };
21    
22 dpavlin 10 my @test_texts = (
23     'This is a test',
24     'of pure-perl bindings',
25     'for HyperEstraier'
26     );
27    
28 dpavlin 6 ok(my $doc = new Search::Estraier::Document, 'new');
29 dpavlin 2
30 dpavlin 9 isa_ok($doc, 'Search::Estraier::Document');
31    
32 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
33 dpavlin 2
34 dpavlin 6 ok($doc->delete, "delete");
35 dpavlin 2
36 dpavlin 6 ok($doc = new Search::Estraier::Document, 'new');
37    
38 dpavlin 2 foreach my $a (keys %{$attr_data}) {
39 dpavlin 8 my $d = $attr_data->{$a} || die;
40     ok($doc->add_attr($a, $d), "add_attr $a");
41     cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d");
42 dpavlin 2 }
43    
44 dpavlin 10 foreach my $t (@test_texts) {
45     ok($doc->add_text($t), "add_text: $t");
46     }
47    
48 dpavlin 6 ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
49 dpavlin 2
50 dpavlin 9 throws_ok { my $text = $doc->texts } qr/return array/, 'texts scalar';
51     ok(my @texts = $doc->texts, 'texts array');
52    
53 dpavlin 6 ok(my $draft = $doc->dump_draft, 'dump_draft');
54 dpavlin 2
55     diag "dump_draft:\n$draft";
56    
57 dpavlin 9 #ok(my $doc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft');
58     #cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
59 dpavlin 2
60 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
61 dpavlin 9 #cmp_ok($doc2->id, '==', -1, 'id');
62 dpavlin 2
63 dpavlin 9 ok(my @attr = $doc->attr_names, 'attr_names');
64 dpavlin 2 diag "attr_names: ", join(',',@attr), "\n";
65    
66     cmp_ok(scalar @attr, '==', 2, 'attr_names');
67    
68 dpavlin 6 ok(! $doc->attr('foobar'), "non-existant attr");
69 dpavlin 2
70     foreach my $a (keys %{$attr_data}) {
71 dpavlin 6 cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a});
72 dpavlin 9 ok($doc->add_attr($a, undef), "delete attribute");
73 dpavlin 2 }
74    
75 dpavlin 10 @attr = $doc->attr_names;
76 dpavlin 6 #diag "attr_names left: ", join(',',$doc->attr_names), "\n";
77 dpavlin 9 cmp_ok(@attr, '==' , 0, "attributes removed");
78 dpavlin 2
79     diag "texts: ", join(',',@texts), "\n";
80 dpavlin 10 ok(eq_array(\@test_texts, \@texts), 'texts');
81 dpavlin 2
82 dpavlin 10 diag Dumper(\@test_texts, \@texts);
83 dpavlin 2
84     SKIP: {
85     skip "est_keywords not implemented", 2;
86    
87 dpavlin 6 my @keywords = $doc->keywords;
88 dpavlin 2 diag "keywords: ", join(',',@keywords), "\n";
89    
90     cmp_ok(scalar @keywords, '==', 1, 'keywords');
91     }
92    
93    
94 dpavlin 9 #ok(my $snippet = $doc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet");
95     #diag "make_snippet:\n$snippet";
96 dpavlin 2
97 dpavlin 9 #ok($doc->scan_words(qw(this is demo)), "scan_words");
98 dpavlin 10
99     diag Dumper($doc);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26