1 |
dpavlin |
827 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use Test::More tests => 4; |
5 |
|
|
use Test::Exception; |
6 |
|
|
use blib; |
7 |
|
|
|
8 |
|
|
use Data::Dump qw/dump/; |
9 |
|
|
use Cwd qw/abs_path/; |
10 |
|
|
|
11 |
|
|
BEGIN { |
12 |
|
|
use_ok( 'WebPAC::Validate' ); |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
my $debug = shift @ARGV; |
16 |
|
|
|
17 |
|
|
ok(my $abs_path = abs_path($0), "abs_path"); |
18 |
|
|
$abs_path =~ s#/[^/]*$#/#; |
19 |
|
|
|
20 |
|
|
ok(my $v = new WebPAC::Validate( |
21 |
|
|
path => "$abs_path/data/validate_test", |
22 |
dpavlin |
828 |
delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ], |
23 |
dpavlin |
827 |
debug => $debug, |
24 |
|
|
), "new"); |
25 |
|
|
|
26 |
|
|
diag "rules = ", dump( $v->{rules} ); |
27 |
|
|
|
28 |
|
|
$v->{rules} = {}; |
29 |
|
|
|
30 |
|
|
sub test_v { |
31 |
|
|
my $row = shift || die "no row?"; |
32 |
|
|
|
33 |
|
|
my $d = dump( $row ); |
34 |
|
|
|
35 |
|
|
$row->{'000'} = [ 42 ]; |
36 |
|
|
|
37 |
|
|
$v->reset_errors; |
38 |
|
|
my $e = $v->validate_rec( $row ); |
39 |
|
|
|
40 |
|
|
diag ">> validate $d\n",dump($e) if ($debug); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
test_v({ |
44 |
dpavlin |
828 |
'900' => [ |
45 |
|
|
{ 'a' => 'a : aa = aaa : a ; a', 'b' => 'b ; b ; b ; b ; a : / z . z . ' }, |
46 |
|
|
{ 'a' => 'a : a : a', 'c' => [ 'a : b ; c', 'a : b ; c / d' ] }, |
47 |
|
|
{ 'a' => 'a : b / c' }, |
48 |
|
|
{ 'a' => 'a : b / c' }, |
49 |
|
|
] |
50 |
dpavlin |
827 |
}); |
51 |
|
|
|
52 |
|
|
diag dump($v->{_delimiters_templates}); |
53 |
|
|
|
54 |
|
|
is_deeply( $v->{_delimiters_templates}, { |
55 |
|
|
900 => { |
56 |
dpavlin |
828 |
"^a : / " => 2, |
57 |
|
|
"^a : : ^c : ; ^c : ; / " => 1, |
58 |
|
|
"^a : = : ; ^b ; ; ; ; : . . " => 1, |
59 |
dpavlin |
827 |
}, |
60 |
|
|
}, 'just subfields and delimiters'); |
61 |
|
|
|