4 use Test::More tests => 51;
8 use Data::Dump qw/dump/;
12 use_ok( 'WebPAC::Validate' );
15 my $debug = shift @ARGV;
17 ok(my $abs_path = abs_path($0), "abs_path");
18 $abs_path =~ s#/[^/]*$#/#;
20 throws_ok { new WebPAC::Validate( no_log => 1 ) } qr/need path/, "new without path";
22 ok(my $v = new WebPAC::Validate(
23 path => "$abs_path/data/validate_test",
27 ok($v->{rules}, "rules exist");
29 is_deeply( $v->{rules}, {
32 '902' => [ 'b', 'c' ],
33 '903' => [ 'a', 'b', 'c' ],
40 throws_ok { $v->validate_errors() } qr/rec/, "validate_rec need rec";
43 my $row = shift || die "no row?";
47 $row->{'000'} = [ 42 ];
50 my $e = $v->validate_errors( $row );
52 diag "validate $d\n",dump($e) if ($debug);
58 ok($tmp = $tmp->{$k}, "found $k");
60 diag "tmp: ",dump($tmp) if ($debug);
62 if (ref($tmp) eq 'HASH') {
65 diag "explanation: $tmp";
69 ok(! $e, "validated $d");
70 diag "expected error: ", dump($e) if($e);
77 }, qw/900 not_repeatable/);
80 '900' => [ qw/foo bar baz/ ]
84 '901' => [ qw/foo bar baz/ ]
85 }, qw/901 missing_subfield/);
88 '901' => [ { 'a' => 42 } ]
92 '901' => [ { 'b' => 42 } ]
93 }, qw/901 subfield extra b/);
96 '902' => [ { 'b' => 1 }, { 'c' => 2 } ]
100 '902' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]
101 }, qw/902 subfield extra a/);
104 '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]
108 '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 }, { 'd' => 3 } ]
109 }, qw/903 subfield extra d/);
114 '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 }, { 'd' => 3 }, { 'e' => 4 } ]
115 }, qw/903 subfield extra/),
116 { 'd' => 1, 'e' => 1 }, 'additional fields d, e');
119 '904' => [ { 'a' => 1, } ]
123 '904' => [ { 'b' => 1 } ]
124 }, qw/904 subfield extra b/);
127 '904' => [ { 'a' => [ 1,2 ] } ]
128 }, qw/904 subfield extra_repeatable a/);
131 '905' => [ { 'a' => [ 1,2 ] } ]
140 '901' => [ qw/foo bar baz/ ],
141 '902' => [ { 'a' => 1, 'b' => [ 1,2 ] } ],
142 '903' => [ { 'a' => [ 1, 2 ], 'c' => 1, } ],
143 '904' => [ { 'b' => 1 } ],
144 '905' => [ { 'a' => 1 } ],
147 diag "errors: ",dump( $v->all_errors );
149 diag "report: ", $v->report;