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

Diff of /trunk/t/1_Document.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4 by dpavlin, Wed Jan 4 13:33:07 2006 UTC revision 97 by dpavlin, Sat Jan 28 18:19:47 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 25;  use Test::More tests => 54;
7    use Test::Exception;
8    use Data::Dumper;
9    
10  BEGIN { use_ok('Search::Estraier') };  BEGIN { use_ok('Search::Estraier') };
11    
# Line 15  BEGIN { use_ok('Search::Estraier') }; Line 17  BEGIN { use_ok('Search::Estraier') };
17  my $attr_data = {  my $attr_data = {
18          '@uri' => 'http://localhost/Search-Estraier/',          '@uri' => 'http://localhost/Search-Estraier/',
19          'size' => 42,          'size' => 42,
20            'zero' => 0,
21            'foo' => 'bar',
22            'empty' => '',
23  };  };
24    
25  ok(my $estdoc = new Search::Estraier::Document, 'new');  my @test_texts = (
26            'This is a test',
27            'of pure-perl bindings',
28            'for HyperEstraier'
29    );
30    
31  ok($estdoc->delete, "delete");  ok(my $doc = new Search::Estraier::Document, 'new');
32    
33  ok($estdoc = new Search::Estraier::Document, 'new');  isa_ok($doc, 'Search::Estraier::Document');
34    
35  foreach my $a (keys %{$attr_data}) {  cmp_ok($doc->id, '==', -1, 'id');
         ok($estdoc->add_attr($a, $attr_data->{$a}), "add_attr $a");  
 }  
   
 ok($estdoc->add_text('This is a demo'), 'add_text');  
 ok($estdoc->add_hidden_text('This is hidden text'), 'add_hidden_text');  
36    
37  ok(my $draft = $estdoc->dump_draft, 'dump_draft');  ok($doc->delete, "delete");
38    
39  diag "dump_draft:\n$draft";  ok($doc = new Search::Estraier::Document, 'new');
40    
41  ok(my $estdoc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft');  foreach my $a (keys %{$attr_data}) {
42  cmp_ok($estdoc2->dump_draft, 'eq', $draft, 'drafts same');          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            cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d");
46    }
47    
48  cmp_ok($estdoc->id, '==', -1, 'id');  foreach my $t (@test_texts) {
49  cmp_ok($estdoc2->id, '==', -1, 'id');          ok($doc->add_text($t), "add_text: $t");
50    }
51    
52  my @attr = $estdoc->attr_names;  ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
 diag "attr_names: ", join(',',@attr), "\n";  
53    
54  cmp_ok(scalar @attr, '==', 2, 'attr_names');  ok(my @texts = $doc->texts, 'texts');
55    
56  ok(! $estdoc->attr('foobar'), "non-existant attr");  ok(my $draft = $doc->dump_draft, 'dump_draft');
57    
58  foreach my $a (keys %{$attr_data}) {  foreach my $a (keys %{$attr_data}) {
59          cmp_ok($attr_data->{$a}, 'eq', $estdoc->attr($a), "attr $a = ".$attr_data->{$a});          my $regex = $a . '=' . $attr_data->{$a};
60          ok($estdoc->add_attr($a, ''), "delete attribute");          like($draft, qr/$regex/, "draft has $regex");
61  }  }
62    
63  #diag "attr_names left: ", join(',',$estdoc->attr_names), "\n";  #diag "dump_draft:\n$draft";
 cmp_ok($estdoc->attr_names, '==' , 0, "attributes removed");  
64    
65  my @texts = $estdoc->texts;  ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');
66  diag "texts: ", join(',',@texts), "\n";  cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
67    
68  cmp_ok(scalar @texts, '==', 1, 'texts');  cmp_ok($doc->id, '==', -1, 'id');
69    cmp_ok($doc2->id, '==', -1, 'id');
70    
71  SKIP: {  ok(my @attr = $doc->attr_names, 'attr_names');
72          skip "est_keywords not implemented", 2;  #diag "attr_names: ", join(',',@attr), "\n";
73    
74          my @keywords = $estdoc->keywords;  cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names');
         diag "keywords: ", join(',',@keywords), "\n";  
75    
76          cmp_ok(scalar @keywords, '==', 1, 'keywords');  ok(! $doc->attr('foobar'), "non-existant attr");
 }  
77    
78    foreach my $a (keys %{$attr_data}) {
79            cmp_ok($doc->attr($a), 'eq', $attr_data->{$a}, "attr $a = ".$attr_data->{$a});
80            ok($doc->add_attr($a, undef), "delete attribute");
81    }
82    
83  ok(my $snippet = $estdoc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet");  @attr = $doc->attr_names;
84  diag "make_snippet:\n$snippet";  #diag "attr_names left: ", join(',',$doc->attr_names), "\n";
85    cmp_ok(@attr, '==' , 0, "attributes removed");
86    
87    #diag "texts: ", join(',',@texts), "\n";
88    ok(eq_array(\@test_texts, \@texts), 'texts');
89    
90    ok(my $cat_text = $doc->cat_texts, 'cat_text');
91    #diag "cat_texts: $cat_text";
92    
93    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  ok($estdoc->scan_words(qw(this is demo)), "scan_words");  #diag Dumper($doc);

Legend:
Removed from v.4  
changed lines
  Added in v.97

  ViewVC Help
Powered by ViewVC 1.1.26