1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use Test::More tests => 54; |
use lib 'lib'; |
|
use Test::Exception; |
|
|
use blib; |
|
5 |
|
|
6 |
use Data::Dump qw/dump/; |
use Test::More tests => 56; |
|
use Cwd qw/abs_path/; |
|
7 |
|
|
8 |
BEGIN { |
BEGIN { |
9 |
|
use_ok( 'WebPAC::Test' ); |
10 |
use_ok( 'WebPAC::Validate' ); |
use_ok( 'WebPAC::Validate' ); |
11 |
} |
} |
12 |
|
|
13 |
my $debug = shift @ARGV; |
ok(my $v = new WebPAC::Validate(%LOG), "new witout path"); |
|
|
|
|
ok(my $abs_path = abs_path($0), "abs_path"); |
|
|
$abs_path =~ s#/[^/]*$#/#; |
|
|
|
|
|
ok(my $v = new WebPAC::Validate( |
|
|
debug => $debug, |
|
|
), "new witout path"); |
|
14 |
|
|
15 |
ok( ! $v->{rules}, 'no path' ); |
ok( ! $v->{rules}, 'no path' ); |
16 |
|
|
17 |
ok($v = new WebPAC::Validate( |
ok($v = new WebPAC::Validate( |
18 |
path => "$abs_path/data/validate_test", |
path => "$abs_path/data/validate_test", |
19 |
debug => $debug, |
%LOG, |
20 |
), "new with path"); |
), "new with path"); |
21 |
|
|
22 |
ok($v->{rules}, "rules exist"); |
ok($v->{rules}, "rules exist"); |
28 |
'903' => [ 'a', 'b', 'c' ], |
'903' => [ 'a', 'b', 'c' ], |
29 |
'904' => [ 'a' ], |
'904' => [ 'a' ], |
30 |
'905' => [ 'a*' ], |
'905' => [ 'a*' ], |
31 |
|
'906' => [ '0' ], |
32 |
}, 'simple rules parsed'); |
}, 'simple rules parsed'); |
33 |
|
|
34 |
diag dump( $v ) if ( $debug ); |
diag dump( $v ) if ( $debug ); |
52 |
'903' => [ 'a', 'b', 'c' ], |
'903' => [ 'a', 'b', 'c' ], |
53 |
'904' => [ 'a' ], |
'904' => [ 'a' ], |
54 |
'905' => [ 'a*' ], |
'905' => [ 'a*' ], |
55 |
|
'906' => [ '0' ], |
56 |
}, 'rules'); |
}, 'rules'); |
57 |
|
|
58 |
ok($v->{rules}, "rules exist"); |
ok($v->{rules}, "rules exist"); |
82 |
if (ref($tmp) eq 'HASH') { |
if (ref($tmp) eq 'HASH') { |
83 |
return $tmp; |
return $tmp; |
84 |
} else { |
} else { |
85 |
diag "explanation: $tmp"; |
diag "explanation: $tmp" if $debug; |
86 |
} |
} |
87 |
} |
} |
88 |
} else { |
} else { |
154 |
'905' => [ ] |
'905' => [ ] |
155 |
}); |
}); |
156 |
|
|
157 |
|
test_v({ |
158 |
|
'906' => [ ] |
159 |
|
}); |
160 |
|
|
161 |
|
test_v({ |
162 |
|
'906' => [ { '0' => 'foo' } ] |
163 |
|
}); |
164 |
|
|
165 |
my $expected_error = { |
my $expected_error = { |
166 |
900 => { not_repeatable => "probably bug in parsing input data" }, |
900 => { not_repeatable => "probably bug in parsing input data" }, |
167 |
901 => { missing_subfield => "a required", "dump" => "baz" }, |
901 => { missing_subfield => "a required", "dump" => "baz" }, |