X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2F1-validate.t;h=bbbc3e94b46a5730832ff6c7e15edee6a3d5aa22;hb=af0dcffdc5f46d7a1f5215d33875927dd435b9a1;hp=52957c57ad4e6433ac24be326a4c657a907ddbda;hpb=b3c448cbf51dabb342e31250ff822230f81a7686;p=webpac2 diff --git a/t/1-validate.t b/t/1-validate.t index 52957c5..bbbc3e9 100755 --- a/t/1-validate.t +++ b/t/1-validate.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 47; +use Test::More tests => 54; use Test::Exception; use blib; @@ -17,12 +17,16 @@ my $debug = shift @ARGV; ok(my $abs_path = abs_path($0), "abs_path"); $abs_path =~ s#/[^/]*$#/#; -throws_ok { new WebPAC::Validate( no_log => 1 ) } qr/need path/, "new without path"; - ok(my $v = new WebPAC::Validate( + debug => $debug, +), "new witout path"); + +ok( ! $v->{rules}, 'no path' ); + +ok($v = new WebPAC::Validate( path => "$abs_path/data/validate_test", debug => $debug, -), "new"); +), "new with path"); ok($v->{rules}, "rules exist"); @@ -33,9 +37,32 @@ is_deeply( $v->{rules}, { '903' => [ 'a', 'b', 'c' ], '904' => [ 'a' ], '905' => [ 'a*' ], +}, 'simple rules parsed'); + +diag dump( $v ) if ( $debug ); + +ok( $v->read_validate_file( "$abs_path/data/validate_test_simple" ), "read_validate_file" ); + +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' ], + '902' => [ 'b', 'c' ], + '903' => [ 'a', 'b', 'c' ], + '904' => [ 'a' ], + '905' => [ 'a*' ], +}, 'rules'); + +ok($v->{rules}, "rules exist"); throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec"; @@ -46,7 +73,7 @@ sub test_v { $row->{'000'} = [ 42 ]; - $v->reset_errors; + $v->reset; my $e = $v->validate_rec( $row ); diag "validate $d\n",dump($e) if ($debug); @@ -136,7 +163,7 @@ test_v({ 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 } }, @@ -162,6 +189,8 @@ $expected_error, 'validate without subfields'); ok(my $r1 = $v->report, 'report'); +diag "report: $r1" if ( $debug ); + is_deeply( test_v({ '900' => 'foo', @@ -173,7 +202,6 @@ is_deeply( }, undef), $expected_error, 'validate with subfields'); - ok(my $r2 = $v->report, 'report'); cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');