1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use Test::More tests => 51; |
use Test::More tests => 54; |
5 |
use Test::Exception; |
use Test::Exception; |
6 |
use blib; |
use blib; |
7 |
|
|
18 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; |
19 |
|
|
20 |
ok(my $v = new WebPAC::Validate( |
ok(my $v = new WebPAC::Validate( |
21 |
path => "$abs_path/data/validate_test_simple", |
debug => $debug, |
22 |
|
), "new witout path"); |
23 |
|
|
24 |
|
ok( ! $v->{rules}, 'no path' ); |
25 |
|
|
26 |
|
ok(my $v = new WebPAC::Validate( |
27 |
|
path => "$abs_path/data/validate_test", |
28 |
debug => $debug, |
debug => $debug, |
29 |
), "new with path"); |
), "new with path"); |
30 |
|
|
31 |
ok($v->{rules}, "rules exist"); |
ok($v->{rules}, "rules exist"); |
32 |
|
|
33 |
is_deeply( $v->{rules}, { |
is_deeply( $v->{rules}, { |
34 |
'900' => [ 'a', 'b', 'c', 'd' ], |
'900' => 1, |
35 |
|
'901' => [ 'a' ], |
36 |
|
'902' => [ 'b', 'c' ], |
37 |
|
'903' => [ 'a', 'b', 'c' ], |
38 |
|
'904' => [ 'a' ], |
39 |
|
'905' => [ 'a*' ], |
40 |
}, 'simple rules parsed'); |
}, 'simple rules parsed'); |
41 |
|
|
42 |
ok($v = new WebPAC::Validate( |
diag dump( $v ) if ( $debug ); |
|
debug => $debug, |
|
|
), "new witout path"); |
|
43 |
|
|
44 |
ok( ! $v->{rules}, 'no path' ); |
ok( $v->read_validate_file( "$abs_path/data/validate_test_simple" ), "read_validate_file" ); |
45 |
|
|
46 |
ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" ); |
diag dump( $v ) if ( $debug ); |
47 |
|
|
48 |
ok($v->{rules}, "rules exist"); |
ok($v->{rules}, "rules exist"); |
49 |
|
|
50 |
is_deeply( $v->{rules}, { |
is_deeply( $v->{rules}, { |
51 |
|
'900' => [ 'a', 'b', 'c', 'd' ], |
52 |
|
}, 'rules parsed'); |
53 |
|
|
54 |
|
ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" ); |
55 |
|
|
56 |
|
is_deeply( $v->{rules}, { |
57 |
'900' => 1, |
'900' => 1, |
58 |
'901' => [ 'a' ], |
'901' => [ 'a' ], |
59 |
'902' => [ 'b', 'c' ], |
'902' => [ 'b', 'c' ], |
60 |
'903' => [ 'a', 'b', 'c' ], |
'903' => [ 'a', 'b', 'c' ], |
61 |
'904' => [ 'a' ], |
'904' => [ 'a' ], |
62 |
'905' => [ 'a*' ], |
'905' => [ 'a*' ], |
63 |
}, 'rules parsed'); |
}, 'rules'); |
64 |
|
|
65 |
|
ok($v->{rules}, "rules exist"); |
66 |
|
|
67 |
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec"; |
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec"; |
68 |
|
|
189 |
|
|
190 |
ok(my $r1 = $v->report, 'report'); |
ok(my $r1 = $v->report, 'report'); |
191 |
|
|
192 |
|
diag "report: $r1" if ( $debug ); |
193 |
|
|
194 |
is_deeply( |
is_deeply( |
195 |
test_v({ |
test_v({ |
196 |
'900' => 'foo', |
'900' => 'foo', |
202 |
}, undef), |
}, undef), |
203 |
$expected_error, 'validate with subfields'); |
$expected_error, 'validate with subfields'); |
204 |
|
|
|
|
|
205 |
ok(my $r2 = $v->report, 'report'); |
ok(my $r2 = $v->report, 'report'); |
206 |
|
|
207 |
cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields'); |
cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields'); |