X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2F2-parse.t;h=36f4da2fee87317aacd2855ef0bf060a32402851;hb=5c610e9b594e5a295a2dfad9b24ead59eda74990;hp=4a081c7de915bd3dbe5925a7dc1a72ac07887d80;hpb=b827a00efe5ce989a0dae18424049fef31d9de9e;p=webpac2 diff --git a/t/2-parse.t b/t/2-parse.t index 4a081c7..36f4da2 100755 --- a/t/2-parse.t +++ b/t/2-parse.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 8; +use Test::More tests => 55; use Test::Exception; use blib; @@ -29,8 +29,112 @@ ok( my $parser = new WebPAC::Parser( config => new WebPAC::Config( path => $config_path ), base_path => $abs_path, + debug => $debug, ), "new"); -ok($parser->{source}, "source exist"); +my $inputs = { + foo => [ qw/foo-input1 foo-input2/ ], + bar => [ qw/bar-input/ ], + baz => [ qw/baz-input/ ], +}; + +foreach my $db (keys %$inputs) { + ok($parser->valid_database($db), "database $db"); + ok($inputs->{$db}, "has known inputs"); + diag "valid inputs = ", dump($inputs->{$db}); + foreach my $i (@{ $inputs->{$db} }) { + ok($parser->valid_database_input($db,$i), "input $i"); + } +} +ok(! $parser->valid_database('non-existant'), "no database"); +ok(! $parser->valid_database_input('foo','non-existant'), "no database input"); + +ok(my $l = $parser->{_lookup_create_key}, "_lookup_create_key"); +ok($parser->{_lookup_create}, "_lookup_create"); +diag "_lookup_create_key = ",dump($l) if ($debug); +foreach my $db (keys %$l) { + foreach my $i (keys %{$l->{$db}}) { + ok(defined($parser->lookup_create_rules($db,$i)), "lookup_create_rules($db/$i)"); + my @keys = sort keys %{$l->{$db}->{$i}}; + ok(@keys, 'have keys'); + my @have_keys = sort $parser->have_lookup_create($db,$i); + ok(@have_keys, 'have_lookup_create'); + ok(eq_array(\@have_keys, \@keys), "found all lookups"); + } +} + +ok(my $n = $parser->{_normalize_source}, "_normalize_source"); +diag "_normalize_source = ",dump($n) if ($debug); +foreach my $db (keys %$n) { + foreach my $i (keys %{$n->{$db}}) { + ok(my $r = $parser->normalize_rules($db,$i), "normalize_source($db/$i)"); + diag "normalize_rules($db,$i) = $r" if ($debug); + cmp_ok($n->{$db}->{$i}, 'eq', $r, "same"); + } +} + +ok(my $d = $parser->{depends}, "depends"); +diag "depends = ",dump($d) if ($debug); + +my $expected_depend = { + foo => { + "foo-input1" => { + bar => { "bar-input" => { "210-a-210-e" => 1, "220-a-220-e" => 1, "230-a-230-e" => 1 } }, + baz => { "baz-input" => { "200-a" => 1 } }, + foo => { "foo-input1" => { 11 => 1 }, "foo-input2" => { 11 => 1 } }, + }, + "foo-input2" => { + bar => { "bar-input" => { "900-x" => 1 } }, + baz => { "baz-input" => { "900-x" => 1 } }, + foo => { "foo-input1" => { "245-a" => 1 }, "foo-input2" => { "245-a" => 1 } }, + }, + }, + bar => { + "bar-input" => { + baz => { "baz-input" => { "900-x" => 1 } }, + foo => { "foo-input1" => { "245-a" => 1 } }, + }, + }, + baz => { + "baz-input" => { + bar => { "bar-input" => { "900-x" => 1 } }, + foo => { "foo-input2" => { "245-a" => 1 } }, + }, + }, +}; + + +is_deeply($d, $expected_depend, "depends correct"); + +foreach my $db (keys %$d) { + foreach my $i (keys %{$d->{$db}}) { + is_deeply($d->{$db}->{$i}, $parser->depends($db,$i), "depend $db/$i"); + } +} + +$config_path = "$abs_path/conf/marc.yml"; + +ok(-e $config_path, "$config_path exists"); + +ok( + my $parser = new WebPAC::Parser( + config => new WebPAC::Config( path => $config_path ), + base_path => $abs_path, + debug => $debug, +), "new"); + +ok(my $marc = $parser->have_rules('marc', 'marc', 'marc-input'), 'have_rules(marc,...)'); + +diag "marc: ",dump($marc) if ($debug); + +is_deeply($marc, { + marc => 1, + marc_compose => 1, + marc_duplicate => 1, + marc_indicators => 1, + marc_leader => 1, + marc_original_order => 1, + marc_remove => 1, + marc_repeatable_subfield => 1, +}, 'catched all marc_*'); -ok($parser->parse, 'parse');