1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use Test::More tests => 47; |
use Test::More tests => 51; |
5 |
use Test::Exception; |
use Test::Exception; |
6 |
use blib; |
use blib; |
7 |
|
|
17 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
18 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; |
19 |
|
|
|
throws_ok { new WebPAC::Validate( no_log => 1 ) } qr/need path/, "new without path"; |
|
|
|
|
20 |
ok(my $v = new WebPAC::Validate( |
ok(my $v = new WebPAC::Validate( |
21 |
path => "$abs_path/data/validate_test", |
path => "$abs_path/data/validate_test_simple", |
22 |
|
debug => $debug, |
23 |
|
), "new with path"); |
24 |
|
|
25 |
|
ok($v->{rules}, "rules exist"); |
26 |
|
|
27 |
|
is_deeply( $v->{rules}, { |
28 |
|
'900' => [ 'a', 'b', 'c', 'd' ], |
29 |
|
}, 'simple rules parsed'); |
30 |
|
|
31 |
|
ok($v = new WebPAC::Validate( |
32 |
debug => $debug, |
debug => $debug, |
33 |
), "new"); |
), "new witout path"); |
34 |
|
|
35 |
|
ok( ! $v->{rules}, 'no path' ); |
36 |
|
|
37 |
|
ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" ); |
38 |
|
|
39 |
ok($v->{rules}, "rules exist"); |
ok($v->{rules}, "rules exist"); |
40 |
|
|
48 |
}, 'rules parsed'); |
}, 'rules parsed'); |
49 |
|
|
50 |
|
|
51 |
|
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec"; |
|
throws_ok { $v->validate_errors() } qr/rec/, "validate_rec need rec"; |
|
52 |
|
|
53 |
sub test_v { |
sub test_v { |
54 |
my $row = shift || die "no row?"; |
my $row = shift || die "no row?"; |
57 |
|
|
58 |
$row->{'000'} = [ 42 ]; |
$row->{'000'} = [ 42 ]; |
59 |
|
|
60 |
$v->reset_errors; |
$v->reset; |
61 |
my $e = $v->validate_errors( $row ); |
my $e = $v->validate_rec( $row ); |
62 |
|
|
63 |
diag "validate $d\n",dump($e) if ($debug); |
diag "validate $d\n",dump($e) if ($debug); |
64 |
|
|