6 use Test::More tests => 60;
11 use_ok( 'WebPAC::Test' );
12 use_ok( 'WebPAC::Parser' );
13 use_ok( 'WebPAC::Config' );
16 my $config_path = "$abs_path/conf/test.yml";
18 ok(-e $config_path, "$config_path exists");
20 throws_ok { new WebPAC::Parser( %LOG ) } qr/WebPAC::Config/, "new without config";
23 my $parser = new WebPAC::Parser(
24 config => new WebPAC::Config( path => $config_path ),
25 base_path => $abs_path,
30 foo => [ qw/foo-input1 foo-input2/ ],
31 bar => [ qw/bar-input/ ],
32 baz => [ qw/baz-input/ ],
35 foreach my $db (keys %$inputs) {
36 ok($parser->valid_database($db), "database $db");
37 ok($inputs->{$db}, "has known inputs");
38 diag "valid inputs = ", dump($inputs->{$db});
39 foreach my $i (@{ $inputs->{$db} }) {
40 ok($parser->valid_database_input($db,$i), "input $i");
43 ok(! $parser->valid_database('non-existant'), "no database");
44 ok(! $parser->valid_database_input('foo','non-existant'), "no database input");
46 ok(my $l = $parser->{_lookup_create_key}, "_lookup_create_key");
47 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");
60 ok(my $n = $parser->{_normalize_source}, "_normalize_source");
61 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_rules($db/$i)");
65 diag "normalize_rules($db,$i) = $r" if ($debug);
66 cmp_ok($n->{$db}->{$i}, 'eq', $r, "same");
70 ok(my $d = $parser->{depends}, "depends");
71 diag "depends = ",dump($d) if ($debug);
73 my $expected_depend = {
76 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 } },
78 foo => { "foo-input1" => { 11 => 1 }, "foo-input2" => { 11 => 1 } },
81 bar => { "bar-input" => { "900-x" => 1 } },
82 baz => { "baz-input" => { "900-x" => 1 } },
83 foo => { "foo-input1" => { "245-a" => 1 }, "foo-input2" => { "245-a" => 1 } },
88 baz => { "baz-input" => { "900-x" => 1 } },
89 foo => { "foo-input1" => { "245-a" => 1 } },
94 bar => { "bar-input" => { "900-x" => 1 } },
95 foo => { "foo-input2" => { "245-a" => 1 } },
101 is_deeply($d, $expected_depend, "depends correct");
103 foreach my $db (keys %$d) {
104 foreach my $i (keys %{$d->{$db}}) {
105 is_deeply($d->{$db}->{$i}, $parser->depends($db,$i), "depend $db/$i");
109 $config_path = "$abs_path/conf/marc.yml";
111 ok(-e $config_path, "$config_path exists");
114 $parser = new WebPAC::Parser(
115 config => new WebPAC::Config( path => $config_path ),
116 base_path => $abs_path,
120 ok(my $marc = $parser->have_rules('marc', 'marc', 'marc-input'), 'have_rules(marc,...)');
122 diag "marc: ",dump($marc) if ($debug);
128 marc_indicators => 1,
130 marc_original_order => 1,
132 marc_repeatable_subfield => 1,
133 }, 'catched all marc_*');
136 $config_path = "$abs_path/conf/sub.yml";
138 ok(-e $config_path, "$config_path exists");
141 $parser = new WebPAC::Parser(
142 config => new WebPAC::Config( path => $config_path ),
143 base_path => $abs_path,
147 ok(my $rules = $parser->normalize_rules('sub','sub-input'), "normalize_rules(sub)");
149 diag "rules: $rules" if $debug;
153 diag "test = ",dump( @test ) if $debug;
155 ok(! $@, "eval: $@" );
157 is_deeply( [ @test ], [ "foo", "foo", "bar >>2<<", "bar >>42<<" ], 'sub executed' );