#!/usr/bin/perl -w
use strict;
-use Test::More tests => 55;
-use Test::Exception;
-use blib;
+use lib 'lib';
+
+use Test::More tests => 60;
-use Data::Dump qw/dump/;
-use Cwd qw/abs_path/;
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 = {
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)");
+ 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(-e $config_path, "$config_path exists");
ok(
- my $parser = new WebPAC::Parser(
+ $parser = new WebPAC::Parser(
config => new WebPAC::Config( path => $config_path ),
base_path => $abs_path,
- debug => $debug,
+ %LOG,
), "new");
-ok(my $marc = $parser->generate_marc('marc','marc-input'), 'generate_marc');
+ok(my $marc = $parser->have_rules('marc', 'marc', 'marc-input'), 'have_rules(marc,...)');
diag "marc: ",dump($marc) if ($debug);
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<<", 1,2,3 ], 'source fixed' );
+