projects
/
webpac2
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
r1670@llin: dpavlin | 2007-11-28 00:13:29 +0100
[webpac2]
/
t
/
1-validate.t
diff --git
a/t/1-validate.t
b/t/1-validate.t
index
1dc8cba
..
734d274
100755
(executable)
--- a/
t/1-validate.t
+++ b/
t/1-validate.t
@@
-1,28
+1,22
@@
#!/usr/bin/perl -w
use strict;
#!/usr/bin/perl -w
use strict;
-use Test::More tests => 51;
-use Test::Exception;
use blib;
use blib;
-use Data::Dump qw/dump/;
-use Cwd qw/abs_path/;
+use Test::More tests => 56;
BEGIN {
BEGIN {
+use_ok( 'WebPAC::Test' );
use_ok( 'WebPAC::Validate' );
}
use_ok( 'WebPAC::Validate' );
}
-
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#/[^/]*$#/#;
-
-my $validate_path = "$abs_path/data/validate_test";
-$validate_path =~ s#//+#/#g;
+ok( ! $v->{rules}, 'no path' );
-ok(
my
$v = new WebPAC::Validate(
- path =>
$validate_path
,
-
debug => $debug
,
+ok($v = new WebPAC::Validate(
+ path =>
"$abs_path/data/validate_test"
,
+
%LOG
,
), "new with path");
ok($v->{rules}, "rules exist");
), "new with path");
ok($v->{rules}, "rules exist");
@@
-34,18
+28,23
@@
is_deeply( $v->{rules}, {
'903' => [ 'a', 'b', 'c' ],
'904' => [ 'a' ],
'905' => [ 'a*' ],
'903' => [ 'a', 'b', 'c' ],
'904' => [ 'a' ],
'905' => [ 'a*' ],
-}, 'rules parsed');
+ '906' => [ '0' ],
+}, 'simple rules parsed');
-ok($v = new WebPAC::Validate(
- debug => $debug,
-), "new witout path");
+diag dump( $v ) if ( $debug );
-ok(
! $v->{rules}, 'no path'
);
+ok(
$v->read_validate_file( "$abs_path/data/validate_test_simple" ), "read_validate_file"
);
-
ok( $v->read_validate_file( $validate_path ), "read_validate_file( $validate_path )"
);
+
diag dump( $v ) if ( $debug
);
ok($v->{rules}, "rules exist");
ok($v->{rules}, "rules exist");
+is_deeply( $v->{rules}, {
+ '900' => [ 'a', 'b', 'c', 'd' ],
+}, 'rules parsed');
+
+ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" );
+
is_deeply( $v->{rules}, {
'900' => 1,
'901' => [ 'a' ],
is_deeply( $v->{rules}, {
'900' => 1,
'901' => [ 'a' ],
@@
-53,8
+52,10
@@
is_deeply( $v->{rules}, {
'903' => [ 'a', 'b', 'c' ],
'904' => [ 'a' ],
'905' => [ 'a*' ],
'903' => [ 'a', 'b', 'c' ],
'904' => [ 'a' ],
'905' => [ 'a*' ],
-}, 'rules parsed');
+ '906' => [ '0' ],
+}, 'rules');
+ok($v->{rules}, "rules exist");
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";
throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";
@@
-81,7
+82,7
@@
sub test_v {
if (ref($tmp) eq 'HASH') {
return $tmp;
} else {
if (ref($tmp) eq 'HASH') {
return $tmp;
} else {
- diag "explanation: $tmp";
+ diag "explanation: $tmp"
if $debug
;
}
}
} else {
}
}
} else {
@@
-153,9
+154,17
@@
test_v({
'905' => [ ]
});
'905' => [ ]
});
+test_v({
+ '906' => [ ]
+});
+
+test_v({
+ '906' => [ { '0' => 'foo' } ]
+});
+
my $expected_error = {
900 => { not_repeatable => "probably bug in parsing input data" },
my $expected_error = {
900 => { not_repeatable => "probably bug in parsing input data" },
- 901 => { missing_subfield => "a required" },
+ 901 => { missing_subfield => "a required"
, "dump" => "baz"
},
902 => {
"dump" => "^a1^b1^b2",
subfield => { extra => { a => 1 }, extra_repeatable => { b => 1 } },
902 => {
"dump" => "^a1^b1^b2",
subfield => { extra => { a => 1 }, extra_repeatable => { b => 1 } },
@@
-181,6
+190,8
@@
$expected_error, 'validate without subfields');
ok(my $r1 = $v->report, 'report');
ok(my $r1 = $v->report, 'report');
+diag "report: $r1" if ( $debug );
+
is_deeply(
test_v({
'900' => 'foo',
is_deeply(
test_v({
'900' => 'foo',
@@
-192,7
+203,6
@@
is_deeply(
}, undef),
$expected_error, 'validate with subfields');
}, undef),
$expected_error, 'validate with subfields');
-
ok(my $r2 = $v->report, 'report');
cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');
ok(my $r2 = $v->report, 'report');
cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');