#!/usr/bin/perl -w
use strict;
-use Test::More tests => 51;
+use Test::More tests => 54;
use Test::Exception;
use blib;
ok(my $abs_path = abs_path($0), "abs_path");
$abs_path =~ s#/[^/]*$#/#;
-my $validate_path = "$abs_path/data/validate_test";
-$validate_path =~ s#//+#/#g;
-
ok(my $v = new WebPAC::Validate(
- path => $validate_path,
+ debug => $debug,
+), "new witout path");
+
+ok( ! $v->{rules}, 'no path' );
+
+ok($v = new WebPAC::Validate(
+ path => "$abs_path/data/validate_test",
debug => $debug,
), "new with path");
'903' => [ 'a', 'b', 'c' ],
'904' => [ 'a' ],
'905' => [ 'a*' ],
-}, 'rules parsed');
+}, 'simple rules parsed');
-ok($v = new WebPAC::Validate(
- debug => $debug,
-), "new witout path");
+diag dump( $v ) if ( $debug );
-ok( ! $v->{rules}, 'no path' );
+ok( $v->read_validate_file( "$abs_path/data/validate_test_simple" ), "read_validate_file" );
-ok( $v->read_validate_file( $validate_path ), "read_validate_file( $validate_path )" );
+diag dump( $v ) if ( $debug );
ok($v->{rules}, "rules exist");
+is_deeply( $v->{rules}, {
+ '900' => [ 'a', 'b', 'c', 'd' ],
+}, 'rules parsed');
+
+ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" );
+
is_deeply( $v->{rules}, {
'900' => 1,
'901' => [ 'a' ],
'903' => [ 'a', 'b', 'c' ],
'904' => [ 'a' ],
'905' => [ 'a*' ],
-}, 'rules parsed');
+}, 'rules');
+ok($v->{rules}, "rules exist");
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";
my $expected_error = {
900 => { not_repeatable => "probably bug in parsing input data" },
- 901 => { missing_subfield => "a required" },
+ 901 => { missing_subfield => "a required", "dump" => "baz" },
902 => {
"dump" => "^a1^b1^b2",
subfield => { extra => { a => 1 }, extra_repeatable => { b => 1 } },
ok(my $r1 = $v->report, 'report');
+diag "report: $r1" if ( $debug );
+
is_deeply(
test_v({
'900' => 'foo',
}, undef),
$expected_error, 'validate with subfields');
-
ok(my $r2 = $v->report, 'report');
cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');