added test file
[webpac2] / t / 1-validate.t
index 70a32f9..5c85050 100755 (executable)
@@ -1,31 +1,22 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 54;
-use Test::Exception;
-use blib;
+use lib 'lib';
 
-use Data::Dump qw/dump/;
-use Cwd qw/abs_path/;
+use Test::More tests => 56;
 
 BEGIN {
+use_ok( 'WebPAC::Test' );
 use_ok( 'WebPAC::Validate' );
 }
 
-my $debug = shift @ARGV;
-
-ok(my $abs_path = abs_path($0), "abs_path");
-$abs_path =~ s#/[^/]*$#/#;
-
-ok(my $v = new WebPAC::Validate(
-       debug => $debug,
-), "new witout path");
+ok(my $v = new WebPAC::Validate(%LOG), "new witout path");
 
 ok( ! $v->{rules}, 'no path' );
 
-ok(my $v = new WebPAC::Validate(
+ok($v = new WebPAC::Validate(
        path => "$abs_path/data/validate_test",
-       debug => $debug,
+       %LOG,
 ), "new with path");
 
 ok($v->{rules}, "rules exist");
@@ -37,6 +28,7 @@ is_deeply( $v->{rules}, {
        '903' => [ 'a', 'b', 'c' ],
        '904' => [ 'a' ],
        '905' => [ 'a*' ],
+       '906' => [ '0' ],
 }, 'simple rules parsed');
 
 diag dump( $v ) if ( $debug );
@@ -60,6 +52,7 @@ is_deeply( $v->{rules}, {
        '903' => [ 'a', 'b', 'c' ],
        '904' => [ 'a' ],
        '905' => [ 'a*' ],
+       '906' => [ '0' ],
 }, 'rules');
 
 ok($v->{rules}, "rules exist");
@@ -89,7 +82,7 @@ sub test_v {
                        if (ref($tmp) eq 'HASH') {
                                return $tmp;
                        } else {
-                               diag "explanation: $tmp";
+                               diag "explanation: $tmp" if $debug;
                        }
                }
        } else {
@@ -161,9 +154,17 @@ test_v({
        '905' => [ ]
 });
 
+test_v({
+       '906' => [ ]
+});
+
+test_v({
+       '906' => [ { '0' => 'foo' } ]
+});
+
 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 } },