/[webpac2]/trunk/t/2-parse.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/2-parse.t

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

revision 703 by dpavlin, Mon Sep 25 13:24:09 2006 UTC revision 949 by dpavlin, Thu Nov 1 00:16:48 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
 use Test::More tests => 26;  
 use Test::Exception;  
4  use blib;  use blib;
5    
6  use Data::Dump qw/dump/;  use Test::More tests => 55;
7  use Cwd qw/abs_path/;  
8  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
9    
10  BEGIN {  BEGIN {
11    use_ok( 'WebPAC::Test' );
12  use_ok( 'WebPAC::Parser' );  use_ok( 'WebPAC::Parser' );
13  use_ok( 'WebPAC::Config' );  use_ok( 'WebPAC::Config' );
14  }  }
15    
 my $debug = shift @ARGV;  
   
 ok(my $abs_path = abs_path($0), "abs_path");  
 $abs_path =~ s#/[^/]*$#/#;  
   
16  my $config_path = "$abs_path/conf/test.yml";  my $config_path = "$abs_path/conf/test.yml";
17    
18  ok(-e $config_path, "$config_path exists");  ok(-e $config_path, "$config_path exists");
19    
20  throws_ok { new WebPAC::Parser( no_log => 1 ) } qr/WebPAC::Config/, "new without config";  throws_ok { new WebPAC::Parser( %LOG ) } qr/WebPAC::Config/, "new without config";
21    
22  ok(  ok(
23          my $parser = new WebPAC::Parser(          my $parser = new WebPAC::Parser(
24                  config => new WebPAC::Config( path => $config_path ),                  config => new WebPAC::Config( path => $config_path ),
25                  base_path => $abs_path,                  base_path => $abs_path,
26                  debug => $debug,                  %LOG
27  ), "new");  ), "new");
28    
29  my $inputs = {  my $inputs = {
# Line 49  foreach my $db (keys %$inputs) { Line 43  foreach my $db (keys %$inputs) {
43  ok(! $parser->valid_database('non-existant'), "no database");  ok(! $parser->valid_database('non-existant'), "no database");
44  ok(! $parser->valid_database_input('foo','non-existant'), "no database input");  ok(! $parser->valid_database_input('foo','non-existant'), "no database input");
45    
46  ok(my $l = $parser->{_lookup_create}, "_lookup_create");  ok(my $l = $parser->{_lookup_create_key}, "_lookup_create_key");
47  diag "_lookup_create = ",dump($l);  ok($parser->{_lookup_create}, "_lookup_create");
48    diag "_lookup_create_key = ",dump($l) if ($debug);
49    foreach my $db (keys %$l) {
50            foreach my $i (keys %{$l->{$db}}) {
51                    ok(defined($parser->lookup_create_rules($db,$i)), "lookup_create_rules($db/$i)");
52                    my @keys = sort keys %{$l->{$db}->{$i}};
53                    ok(@keys, 'have keys');
54                    my @have_keys = sort $parser->have_lookup_create($db,$i);
55                    ok(@have_keys, 'have_lookup_create');
56                    ok(eq_array(\@have_keys, \@keys), "found all lookups");
57            }
58    }
59    
60  ok(my $n = $parser->{_normalize_source}, "_normalize_source");  ok(my $n = $parser->{_normalize_source}, "_normalize_source");
61  diag "_normalize_source = ",dump($n);  diag "_normalize_source = ",dump($n) if ($debug);
62    foreach my $db (keys %$n) {
63            foreach my $i (keys %{$n->{$db}}) {
64                    ok(my $r = $parser->normalize_rules($db,$i), "normalize_source($db/$i)");
65                    diag "normalize_rules($db,$i) = $r" if ($debug);
66                    cmp_ok($n->{$db}->{$i}, 'eq', $r, "same");
67            }
68    }
69    
70  ok(my $d = $parser->{depends}, "depends");  ok(my $d = $parser->{depends}, "depends");
71  diag "depends = ",dump($d);  diag "depends = ",dump($d) if ($debug);
72    
73  my $expected_depend = {  my $expected_depend = {
74     foo => {     foo => {
75              "foo-input1" => {              "foo-input1" => {
76                                bar => { "bar-input" => { "200-a-200-e" => 1 } },                                bar => { "bar-input" => { "210-a-210-e" => 1, "220-a-220-e" => 1, "230-a-230-e" => 1 } },
77                                baz => { "baz-input" => { "200-a" => 1 } },                                baz => { "baz-input" => { "200-a" => 1 } },
78                                foo => { "foo-input1" => { 11 => 1 }, "foo-input2" => { 11 => 1 } },                                foo => { "foo-input1" => { 11 => 1 }, "foo-input2" => { 11 => 1 } },
79                              },                              },
# Line 93  foreach my $db (keys %$d) { Line 105  foreach my $db (keys %$d) {
105                  is_deeply($d->{$db}->{$i}, $parser->depends($db,$i), "depend $db/$i");                  is_deeply($d->{$db}->{$i}, $parser->depends($db,$i), "depend $db/$i");
106          }          }
107  }  }
108    
109    $config_path = "$abs_path/conf/marc.yml";
110    
111    ok(-e $config_path, "$config_path exists");
112    
113    ok(
114            my $parser = new WebPAC::Parser(
115                    config => new WebPAC::Config( path => $config_path ),
116                    base_path => $abs_path,
117                    %LOG,
118    ), "new");
119    
120    ok(my $marc = $parser->have_rules('marc', 'marc', 'marc-input'), 'have_rules(marc,...)');
121    
122    diag "marc: ",dump($marc) if ($debug);
123    
124    is_deeply($marc, {
125            marc                                            => 1,
126            marc_compose                            => 1,
127            marc_duplicate                          => 1,
128            marc_indicators                         => 1,
129            marc_leader                                     => 1,
130            marc_original_order                     => 1,
131            marc_remove                                     => 1,
132            marc_repeatable_subfield        => 1,
133    }, 'catched all marc_*');
134    

Legend:
Removed from v.703  
changed lines
  Added in v.949

  ViewVC Help
Powered by ViewVC 1.1.26