/[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 12 by dpavlin, Wed Jan 4 19:28:30 2006 UTC revision 95 by dpavlin, Sat Jan 28 17:55:48 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 30;  use Test::More tests => 45;
7  use Test::Exception;  use Test::Exception;
8  use Data::Dumper;  use Data::Dumper;
9    
# Line 17  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  };  };
23    
24  my @test_texts = (  my @test_texts = (
# Line 36  ok($doc->delete, "delete"); Line 38  ok($doc->delete, "delete");
38  ok($doc = new Search::Estraier::Document, 'new');  ok($doc = new Search::Estraier::Document, 'new');
39    
40  foreach my $a (keys %{$attr_data}) {  foreach my $a (keys %{$attr_data}) {
41          my $d = $attr_data->{$a} || die;          my $d = $attr_data->{$a};
42          ok($doc->add_attr($a, $d), "add_attr $a");          ok($doc->add_attr($a, $d), "add_attr $a = $d");
43            diag "draft:\n",$doc->dump_draft,Dumper($doc->{attrs});
44          cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d");          cmp_ok($doc->attr($a), 'eq', $d, "attr $a = $d");
45  }  }
46    
# Line 47  foreach my $t (@test_texts) { Line 50  foreach my $t (@test_texts) {
50    
51  ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');  ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
52    
53  throws_ok { my $text = $doc->texts } qr/return array/, 'texts scalar';  ok(my @texts = $doc->texts, 'texts');
 ok(my @texts = $doc->texts, 'texts array');  
54    
55  ok(my $draft = $doc->dump_draft, 'dump_draft');  ok(my $draft = $doc->dump_draft, 'dump_draft');
56    
57  diag "dump_draft:\n$draft";  #diag "dump_draft:\n$draft";
58    
59  #ok(my $doc2 = new_from_draft Search::Estraier::Document($draft), 'new_from_draft');  ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');
60  #cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');  cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
61    
62  cmp_ok($doc->id, '==', -1, 'id');  cmp_ok($doc->id, '==', -1, 'id');
63  #cmp_ok($doc2->id, '==', -1, 'id');  cmp_ok($doc2->id, '==', -1, 'id');
64    
65  ok(my @attr = $doc->attr_names, 'attr_names');  ok(my @attr = $doc->attr_names, 'attr_names');
66  diag "attr_names: ", join(',',@attr), "\n";  #diag "attr_names: ", join(',',@attr), "\n";
67    
68  cmp_ok(scalar @attr, '==', 2, 'attr_names');  cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names');
69    
70  ok(! $doc->attr('foobar'), "non-existant attr");  ok(! $doc->attr('foobar'), "non-existant attr");
71    
72  foreach my $a (keys %{$attr_data}) {  foreach my $a (keys %{$attr_data}) {
73          cmp_ok($attr_data->{$a}, 'eq', $doc->attr($a), "attr $a = ".$attr_data->{$a});          cmp_ok($doc->attr($a), 'eq', $attr_data->{$a}, "attr $a = ".$attr_data->{$a});
74          ok($doc->add_attr($a, undef), "delete attribute");          ok($doc->add_attr($a, undef), "delete attribute");
75  }  }
76    
# Line 76  foreach my $a (keys %{$attr_data}) { Line 78  foreach my $a (keys %{$attr_data}) {
78  #diag "attr_names left: ", join(',',$doc->attr_names), "\n";  #diag "attr_names left: ", join(',',$doc->attr_names), "\n";
79  cmp_ok(@attr, '==' , 0, "attributes removed");  cmp_ok(@attr, '==' , 0, "attributes removed");
80    
81  diag "texts: ", join(',',@texts), "\n";  #diag "texts: ", join(',',@texts), "\n";
82  ok(eq_array(\@test_texts, \@texts), 'texts');  ok(eq_array(\@test_texts, \@texts), 'texts');
83    
84  ok(my $cat_text = $doc->cat_texts, 'cat_text');  ok(my $cat_text = $doc->cat_texts, 'cat_text');
85  diag "cat_texts: $cat_text";  #diag "cat_texts: $cat_text";
86    
87    ok($doc = new Search::Estraier::Document, 'new empty');
88  SKIP: {  ok(! $doc->texts, 'texts');
89          skip "est_keywords not implemented", 2;  cmp_ok($doc->dump_draft, 'eq', "\n", 'dump_draft');
90    cmp_ok($doc->id, '==', -1, 'id');
91          my @keywords = $doc->keywords;  ok(! $doc->attr_names, 'attr_names');
92          diag "keywords: ", join(',',@keywords), "\n";  ok(! $doc->attr(undef), 'attr');
93    ok(! $doc->cat_texts, 'cat_texts');
         cmp_ok(scalar @keywords, '==', 1, 'keywords');  
 }  
   
   
 #ok(my $snippet = $doc->make_snippet(480, 96, 96, qw(demo is)), "make_snippet");  
 #diag "make_snippet:\n$snippet";  
   
 #ok($doc->scan_words(qw(this is demo)), "scan_words");  
94    
95  #diag Dumper($doc);  #diag Dumper($doc);

Legend:
Removed from v.12  
changed lines
  Added in v.95

  ViewVC Help
Powered by ViewVC 1.1.26