/[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 97 - (hide annotations)
Sat Jan 28 18:19:47 2006 UTC (18 years, 3 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2537 byte(s)
another fix for empty values
1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4     use blib;
5    
6 dpavlin 97 use Test::More tests => 54;
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 dpavlin 95 'zero' => 0,
21     'foo' => 'bar',
22 dpavlin 97 'empty' => '',
23 dpavlin 2 };
24    
25 dpavlin 10 my @test_texts = (
26     'This is a test',
27     'of pure-perl bindings',
28     'for HyperEstraier'
29     );
30    
31 dpavlin 6 ok(my $doc = new Search::Estraier::Document, 'new');
32 dpavlin 2
33 dpavlin 9 isa_ok($doc, 'Search::Estraier::Document');
34    
35 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
36 dpavlin 2
37 dpavlin 6 ok($doc->delete, "delete");
38 dpavlin 2
39 dpavlin 6 ok($doc = new Search::Estraier::Document, 'new');
40    
41 dpavlin 2 foreach my $a (keys %{$attr_data}) {
42 dpavlin 95 my $d = $attr_data->{$a};
43     ok($doc->add_attr($a, $d), "add_attr $a = $d");
44     diag "draft:\n",$doc->dump_draft,Dumper($doc->{attrs});
45 dpavlin 8 cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d");
46 dpavlin 2 }
47    
48 dpavlin 10 foreach my $t (@test_texts) {
49     ok($doc->add_text($t), "add_text: $t");
50     }
51    
52 dpavlin 6 ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
53 dpavlin 2
54 dpavlin 60 ok(my @texts = $doc->texts, 'texts');
55 dpavlin 9
56 dpavlin 6 ok(my $draft = $doc->dump_draft, 'dump_draft');
57 dpavlin 2
58 dpavlin 97 foreach my $a (keys %{$attr_data}) {
59     my $regex = $a . '=' . $attr_data->{$a};
60     like($draft, qr/$regex/, "draft has $regex");
61     }
62    
63 dpavlin 26 #diag "dump_draft:\n$draft";
64 dpavlin 2
65 dpavlin 14 ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');
66     cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
67 dpavlin 2
68 dpavlin 6 cmp_ok($doc->id, '==', -1, 'id');
69 dpavlin 14 cmp_ok($doc2->id, '==', -1, 'id');
70 dpavlin 2
71 dpavlin 9 ok(my @attr = $doc->attr_names, 'attr_names');
72 dpavlin 26 #diag "attr_names: ", join(',',@attr), "\n";
73 dpavlin 2
74 dpavlin 95 cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names');
75 dpavlin 2
76 dpavlin 6 ok(! $doc->attr('foobar'), "non-existant attr");
77 dpavlin 2
78     foreach my $a (keys %{$attr_data}) {
79 dpavlin 95 cmp_ok($doc->attr($a), 'eq', $attr_data->{$a}, "attr $a = ".$attr_data->{$a});
80 dpavlin 9 ok($doc->add_attr($a, undef), "delete attribute");
81 dpavlin 2 }
82    
83 dpavlin 10 @attr = $doc->attr_names;
84 dpavlin 6 #diag "attr_names left: ", join(',',$doc->attr_names), "\n";
85 dpavlin 9 cmp_ok(@attr, '==' , 0, "attributes removed");
86 dpavlin 2
87 dpavlin 26 #diag "texts: ", join(',',@texts), "\n";
88 dpavlin 10 ok(eq_array(\@test_texts, \@texts), 'texts');
89 dpavlin 2
90 dpavlin 12 ok(my $cat_text = $doc->cat_texts, 'cat_text');
91 dpavlin 26 #diag "cat_texts: $cat_text";
92 dpavlin 12
93 dpavlin 60 ok($doc = new Search::Estraier::Document, 'new empty');
94     ok(! $doc->texts, 'texts');
95     cmp_ok($doc->dump_draft, 'eq', "\n", 'dump_draft');
96     cmp_ok($doc->id, '==', -1, 'id');
97     ok(! $doc->attr_names, 'attr_names');
98     ok(! $doc->attr(undef), 'attr');
99     ok(! $doc->cat_texts, 'cat_texts');
100    
101 dpavlin 12 #diag Dumper($doc);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26