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 |
|
|
20 |
throws_ok { new WebPAC::Validate( no_log => 1 ) } qr/need path/, "new without path"; |
my $validate_path = "$abs_path/data/validate_test"; |
21 |
|
$validate_path =~ s#//+#/#g; |
22 |
|
|
23 |
ok(my $v = new WebPAC::Validate( |
ok(my $v = new WebPAC::Validate( |
24 |
path => "$abs_path/data/validate_test", |
path => $validate_path, |
25 |
debug => $debug, |
debug => $debug, |
26 |
), "new"); |
), "new with path"); |
27 |
|
|
28 |
ok($v->{rules}, "rules exist"); |
ok($v->{rules}, "rules exist"); |
29 |
|
|
36 |
'905' => [ 'a*' ], |
'905' => [ 'a*' ], |
37 |
}, 'rules parsed'); |
}, 'rules parsed'); |
38 |
|
|
39 |
|
ok($v = new WebPAC::Validate( |
40 |
|
debug => $debug, |
41 |
|
), "new witout path"); |
42 |
|
|
43 |
|
ok( ! $v->{rules}, 'no path' ); |
44 |
|
|
45 |
|
ok( $v->read_validate_file( $validate_path ), "read_validate_file( $validate_path )" ); |
46 |
|
|
47 |
|
ok($v->{rules}, "rules exist"); |
48 |
|
|
49 |
|
is_deeply( $v->{rules}, { |
50 |
|
'900' => 1, |
51 |
|
'901' => [ 'a' ], |
52 |
|
'902' => [ 'b', 'c' ], |
53 |
|
'903' => [ 'a', 'b', 'c' ], |
54 |
|
'904' => [ 'a' ], |
55 |
|
'905' => [ 'a*' ], |
56 |
|
}, 'rules parsed'); |
57 |
|
|
58 |
|
|
59 |
throws_ok { $v->validate_errors() } qr/rec/, "validate_rec need rec"; |
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec"; |
60 |
|
|
61 |
sub test_v { |
sub test_v { |
62 |
my $row = shift || die "no row?"; |
my $row = shift || die "no row?"; |
65 |
|
|
66 |
$row->{'000'} = [ 42 ]; |
$row->{'000'} = [ 42 ]; |
67 |
|
|
68 |
$v->reset_errors; |
$v->reset; |
69 |
my $e = $v->validate_errors( $row ); |
my $e = $v->validate_rec( $row ); |
70 |
|
|
71 |
diag "validate $d\n",dump($e) if ($debug); |
diag "validate $d\n",dump($e) if ($debug); |
72 |
|
|