/[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

Contents of /trunk/t/1_Document.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (show annotations)
Sat Jan 7 00:00:15 2006 UTC (18 years, 3 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2289 byte(s)
added few checks to better handle empty documents, array return is not enforced any more.
1 #!/usr/bin/perl -w
2
3 use strict;
4 use blib;
5
6 use Test::More tests => 37;
7 use Test::Exception;
8 use Data::Dumper;
9
10 BEGIN { use_ok('Search::Estraier') };
11
12 #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 my $attr_data = {
18 '@uri' => 'http://localhost/Search-Estraier/',
19 'size' => 42,
20 };
21
22 my @test_texts = (
23 'This is a test',
24 'of pure-perl bindings',
25 'for HyperEstraier'
26 );
27
28 ok(my $doc = new Search::Estraier::Document, 'new');
29
30 isa_ok($doc, 'Search::Estraier::Document');
31
32 cmp_ok($doc->id, '==', -1, 'id');
33
34 ok($doc->delete, "delete");
35
36 ok($doc = new Search::Estraier::Document, 'new');
37
38 foreach my $a (keys %{$attr_data}) {
39 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 }
43
44 foreach my $t (@test_texts) {
45 ok($doc->add_text($t), "add_text: $t");
46 }
47
48 ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
49
50 ok(my @texts = $doc->texts, 'texts');
51
52 ok(my $draft = $doc->dump_draft, 'dump_draft');
53
54 #diag "dump_draft:\n$draft";
55
56 ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');
57 cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
58
59 cmp_ok($doc->id, '==', -1, 'id');
60 cmp_ok($doc2->id, '==', -1, 'id');
61
62 ok(my @attr = $doc->attr_names, 'attr_names');
63 #diag "attr_names: ", join(',',@attr), "\n";
64
65 cmp_ok(scalar @attr, '==', 2, 'attr_names');
66
67 ok(! $doc->attr('foobar'), "non-existant attr");
68
69 foreach my $a (keys %{$attr_data}) {
70 cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a});
71 ok($doc->add_attr($a, undef), "delete attribute");
72 }
73
74 @attr = $doc->attr_names;
75 #diag "attr_names left: ", join(',',$doc->attr_names), "\n";
76 cmp_ok(@attr, '==' , 0, "attributes removed");
77
78 #diag "texts: ", join(',',@texts), "\n";
79 ok(eq_array(\@test_texts, \@texts), 'texts');
80
81 ok(my $cat_text = $doc->cat_texts, 'cat_text');
82 #diag "cat_texts: $cat_text";
83
84 ok($doc = new Search::Estraier::Document, 'new empty');
85 ok(! $doc->texts, 'texts');
86 cmp_ok($doc->dump_draft, 'eq', "\n", 'dump_draft');
87 cmp_ok($doc->id, '==', -1, 'id');
88 ok(! $doc->attr_names, 'attr_names');
89 ok(! $doc->attr(undef), 'attr');
90 ok(! $doc->cat_texts, 'cat_texts');
91
92 #diag Dumper($doc);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26