/[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 9 - (hide annotations)
Wed Jan 4 15:28:39 2006 UTC (18 years, 3 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2231 byte(s)
added texts, fixed add_attr to delete atributes, tests now pass
1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 9 use Test::More tests => 27;
7     use Test::Exception;
8 dpavlin 2
9     BEGIN { use_ok('Search::Estraier') };
10    
11 dpavlin 4 #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 dpavlin 2 my $attr_data = {
17     '@uri' => 'http://localhost/Search-Estraier/',
18     'size' => 42,
19     };
20    
21 dpavlin 6 ok(my $doc = new Search::Estraier::Document, 'new');
22 dpavlin 2
23 dpavlin 9 isa_ok($doc, 'Search::Estraier::Document');
24    
25 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
26 dpavlin 2
27 dpavlin 6 ok($doc->delete, "delete");
28 dpavlin 2
29 dpavlin 6 ok($doc = new Search::Estraier::Document, 'new');
30    
31 dpavlin 2 foreach my $a (keys %{$attr_data}) {
32 dpavlin 8 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 dpavlin 2 }
36    
37 dpavlin 6 ok($doc->add_text('This is a demo'), 'add_text');
38     ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
39 dpavlin 2
40 dpavlin 9 throws_ok { my $text = $doc->texts } qr/return array/, 'texts scalar';
41     ok(my @texts = $doc->texts, 'texts array');
42    
43 dpavlin 6 ok(my $draft = $doc->dump_draft, 'dump_draft');
44 dpavlin 2
45     diag "dump_draft:\n$draft";
46    
47 dpavlin 9 #ok(my $doc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft');
48     #cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
49 dpavlin 2
50 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
51 dpavlin 9 #cmp_ok($doc2->id, '==', -1, 'id');
52 dpavlin 2
53 dpavlin 9 ok(my @attr = $doc->attr_names, 'attr_names');
54 dpavlin 2 diag "attr_names: ", join(',',@attr), "\n";
55    
56     cmp_ok(scalar @attr, '==', 2, 'attr_names');
57    
58 dpavlin 6 ok(! $doc->attr('foobar'), "non-existant attr");
59 dpavlin 2
60     foreach my $a (keys %{$attr_data}) {
61 dpavlin 6 cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a});
62 dpavlin 9 ok($doc->add_attr($a, undef), "delete attribute");
63 dpavlin 2 }
64    
65 dpavlin 9 @attr = $doc->attr_names, 'attr_names';
66 dpavlin 6 #diag "attr_names left: ", join(',',$doc->attr_names), "\n";
67 dpavlin 9 cmp_ok(@attr, '==' , 0, "attributes removed");
68 dpavlin 2
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 dpavlin 6 my @keywords = $doc->keywords;
77 dpavlin 2 diag "keywords: ", join(',',@keywords), "\n";
78    
79     cmp_ok(scalar @keywords, '==', 1, 'keywords');
80     }
81    
82    
83 dpavlin 9 #ok(my $snippet = $doc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet");
84     #diag "make_snippet:\n$snippet";
85 dpavlin 2
86 dpavlin 9 #ok($doc->scan_words(qw(this is demo)), "scan_words");

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26