X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2F2-parse.t;h=1c242312fafca23fbe63e2fe6e632977d3c2b930;hb=5afbb46eafaaf540446794c65776142055397484;hp=70b65f9d94ac43e1826392c12881cbb55f7a5460;hpb=82c1988c711215c894b0466c7ac43fbc039014f7;p=webpac2 diff --git a/t/2-parse.t b/t/2-parse.t index 70b65f9..1c24231 100755 --- a/t/2-parse.t +++ b/t/2-parse.t @@ -1,35 +1,29 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 26; -use Test::Exception; use blib; -use Data::Dump qw/dump/; -use Cwd qw/abs_path/; +use Test::More tests => 60; + use YAML qw/LoadFile/; BEGIN { +use_ok( 'WebPAC::Test' ); use_ok( 'WebPAC::Parser' ); use_ok( 'WebPAC::Config' ); } -my $debug = shift @ARGV; - -ok(my $abs_path = abs_path($0), "abs_path"); -$abs_path =~ s#/[^/]*$#/#; - my $config_path = "$abs_path/conf/test.yml"; ok(-e $config_path, "$config_path exists"); -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"; ok( my $parser = new WebPAC::Parser( config => new WebPAC::Config( path => $config_path ), base_path => $abs_path, - debug => $debug, + %LOG ), "new"); my $inputs = { @@ -49,14 +43,32 @@ foreach my $db (keys %$inputs) { 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}, "_lookup_create"); -diag "_lookup_create = ",dump($l); +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); +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_rules($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); +diag "depends = ",dump($d) if ($debug); my $expected_depend = { foo => { @@ -93,3 +105,54 @@ foreach my $db (keys %$d) { 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( + $parser = new WebPAC::Parser( + config => new WebPAC::Config( path => $config_path ), + base_path => $abs_path, + %LOG, +), "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_*'); + + +$config_path = "$abs_path/conf/sub.yml"; + +ok(-e $config_path, "$config_path exists"); + +ok( + $parser = new WebPAC::Parser( + config => new WebPAC::Config( path => $config_path ), + base_path => $abs_path, + %LOG, +), "new"); + +ok(my $rules = $parser->normalize_rules('sub','sub-input'), "normalize_rules(sub)"); + +diag "rules: $rules" if $debug; + +our @test; +eval $rules; +diag "test = ",dump( @test ) if $debug; + +ok(! $@, "eval: $@" ); + +is_deeply( [ @test ], [ "foo", "foo", "bar >>2<<", "bar >>42<<" ], 'sub executed' ); +