/[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 165 by dpavlin, Sat Jan 28 19:19:25 2006 UTC revision 166 by dpavlin, Sun Aug 6 12:48:02 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 54;  use Test::More tests => 55;
7  use Test::Exception;  use Test::Exception;
8  use Data::Dumper;  use Data::Dumper;
9    
# Line 13  BEGIN { use_ok('Search::Estraier') }; Line 13  BEGIN { use_ok('Search::Estraier') };
13    
14  #cmp_ok(Search::Estraier::Document::_s("  this  is a  text  "), 'eq', 'this is a text', '_s - strip spaces');  #cmp_ok(Search::Estraier::Document::_s("  this  is a  text  "), 'eq', 'this is a text', '_s - strip spaces');
15    
16    my $debug = shift @ARGV;
17    
18  my $attr_data = {  my $attr_data = {
19          '@uri' => 'http://localhost/Search-Estraier/',          '@uri' => 'http://localhost/Search-Estraier/',
# Line 28  my @test_texts = ( Line 29  my @test_texts = (
29          'for HyperEstraier'          'for HyperEstraier'
30  );  );
31    
32    my $vectors = {
33            'foo' => 42,
34            'bar' => 100,
35            'baz' => 0,
36    };
37    
38  ok(my $doc = new Search::Estraier::Document, 'new');  ok(my $doc = new Search::Estraier::Document, 'new');
39    
40  isa_ok($doc, 'Search::Estraier::Document');  isa_ok($doc, 'Search::Estraier::Document');
# Line 51  foreach my $t (@test_texts) { Line 58  foreach my $t (@test_texts) {
58    
59  ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');  ok($doc->add_hidden_text('This is hidden text'), 'add_hidden_text');
60    
61    ok($doc->add_vectors( %{ $vectors } ), 'add_vectors');
62    
63    diag "current doc: ", Dumper($doc) if ($debug);
64    
65  ok(my @texts = $doc->texts, 'texts');  ok(my @texts = $doc->texts, 'texts');
66    
67  ok(my $draft = $doc->dump_draft, 'dump_draft');  ok(my $draft = $doc->dump_draft, 'dump_draft');
# Line 60  foreach my $a (keys %{$attr_data}) { Line 71  foreach my $a (keys %{$attr_data}) {
71          like($draft, qr/$regex/, "draft has $regex");          like($draft, qr/$regex/, "draft has $regex");
72  }  }
73    
74  #diag "dump_draft:\n$draft";  diag "dump_draft:\n$draft" if ($debug);
75    
76  ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');  ok(my $doc2 = new Search::Estraier::Document($draft), 'new from draft');
77    diag "doc from draft: ", Dumper($doc2) if ($debug);
78  cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');  cmp_ok($doc2->dump_draft, 'eq', $draft, 'drafts same');
79    
80  cmp_ok($doc->id, '==', -1, 'id');  cmp_ok($doc->id, '==', -1, 'id');
81  cmp_ok($doc2->id, '==', -1, 'id');  cmp_ok($doc2->id, '==', -1, 'id');
82    
83  ok(my @attr = $doc->attr_names, 'attr_names');  ok(my @attr = $doc->attr_names, 'attr_names');
84  #diag "attr_names: ", join(',',@attr), "\n";  diag "attr_names: ", join(',',@attr), "\n" if ($debug);
85    
86  cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names');  cmp_ok(scalar @attr, '==', keys %{$attr_data}, 'attr_names');
87    
# Line 81  foreach my $a (keys %{$attr_data}) { Line 93  foreach my $a (keys %{$attr_data}) {
93  }  }
94    
95  @attr = $doc->attr_names;  @attr = $doc->attr_names;
96  #diag "attr_names left: ", join(',',$doc->attr_names), "\n";  diag "attr_names left: ", join(',',$doc->attr_names), "\n" if ($debug);
97  cmp_ok(@attr, '==' , 0, "attributes removed");  cmp_ok(@attr, '==' , 0, "attributes removed");
98    
99  #diag "texts: ", join(',',@texts), "\n";  diag "texts: ", join(',',@texts), "\n" if ($debug);
100  ok(eq_array(\@test_texts, \@texts), 'texts');  ok(eq_array(\@test_texts, \@texts), 'texts');
101    
102  ok(my $cat_text = $doc->cat_texts, 'cat_text');  ok(my $cat_text = $doc->cat_texts, 'cat_text');
103  #diag "cat_texts: $cat_text";  diag "cat_texts: $cat_text" if ($debug);
104    
105  ok($doc = new Search::Estraier::Document, 'new empty');  ok($doc = new Search::Estraier::Document, 'new empty');
106  ok(! $doc->texts, 'texts');  ok(! $doc->texts, 'texts');
# Line 98  ok(! $doc->attr_names, 'attr_names'); Line 110  ok(! $doc->attr_names, 'attr_names');
110  ok(! $doc->attr(undef), 'attr');  ok(! $doc->attr(undef), 'attr');
111  ok(! $doc->cat_texts, 'cat_texts');  ok(! $doc->cat_texts, 'cat_texts');
112    
 #diag Dumper($doc);  

Legend:
Removed from v.165  
changed lines
  Added in v.166

  ViewVC Help
Powered by ViewVC 1.1.26