/[webpac2]/trunk/t/1-validate.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/1-validate.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 857 by dpavlin, Sun May 27 16:49:15 2007 UTC revision 949 by dpavlin, Thu Nov 1 00:16:48 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
 use Test::More tests => 51;  
 use Test::Exception;  
4  use blib;  use blib;
5    
6  use Data::Dump qw/dump/;  use Test::More tests => 54;
 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");
14    
15  ok(my $abs_path = abs_path($0), "abs_path");  ok( ! $v->{rules}, 'no path' );
 $abs_path =~ s#/[^/]*$#/#;  
   
 my $validate_path = "$abs_path/data/validate_test";  
 $validate_path =~ s#//+#/#g;  
16    
17  ok(my $v = new WebPAC::Validate(  ok($v = new WebPAC::Validate(
18          path => $validate_path,          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");
# Line 34  is_deeply( $v->{rules}, { Line 28  is_deeply( $v->{rules}, {
28          '903' => [ 'a', 'b', 'c' ],          '903' => [ 'a', 'b', 'c' ],
29          '904' => [ 'a' ],          '904' => [ 'a' ],
30          '905' => [ 'a*' ],          '905' => [ 'a*' ],
31  }, 'rules parsed');  }, 'simple rules parsed');
32    
33  ok($v = new WebPAC::Validate(  diag dump( $v ) if ( $debug );
         debug => $debug,  
 ), "new witout path");  
34    
35  ok( ! $v->{rules}, 'no path' );  ok( $v->read_validate_file( "$abs_path/data/validate_test_simple" ), "read_validate_file" );
36    
37  ok( $v->read_validate_file( $validate_path ), "read_validate_file( $validate_path )" );  diag dump( $v ) if ( $debug );
38    
39  ok($v->{rules}, "rules exist");  ok($v->{rules}, "rules exist");
40    
41  is_deeply( $v->{rules}, {  is_deeply( $v->{rules}, {
42            '900' => [ 'a', 'b', 'c', 'd' ],
43    }, 'rules parsed');
44    
45    ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" );
46    
47    is_deeply( $v->{rules}, {
48          '900' => 1,          '900' => 1,
49          '901' => [ 'a' ],          '901' => [ 'a' ],
50          '902' => [ 'b', 'c' ],          '902' => [ 'b', 'c' ],
51          '903' => [ 'a', 'b', 'c' ],          '903' => [ 'a', 'b', 'c' ],
52          '904' => [ 'a' ],          '904' => [ 'a' ],
53          '905' => [ 'a*' ],          '905' => [ 'a*' ],
54  }, 'rules parsed');  }, 'rules');
55    
56    ok($v->{rules}, "rules exist");
57    
58  throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";  throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";
59    
# Line 81  sub test_v { Line 80  sub test_v {
80                          if (ref($tmp) eq 'HASH') {                          if (ref($tmp) eq 'HASH') {
81                                  return $tmp;                                  return $tmp;
82                          } else {                          } else {
83                                  diag "explanation: $tmp";                                  diag "explanation: $tmp" if $debug;
84                          }                          }
85                  }                  }
86          } else {          } else {
# Line 155  test_v({ Line 154  test_v({
154    
155  my $expected_error = {  my $expected_error = {
156     900 => { not_repeatable => "probably bug in parsing input data" },     900 => { not_repeatable => "probably bug in parsing input data" },
157     901 => { missing_subfield => "a required" },     901 => { missing_subfield => "a required", "dump" => "baz" },
158     902 => {     902 => {
159              "dump"   => "^a1^b1^b2",              "dump"   => "^a1^b1^b2",
160              subfield => { extra => { a => 1 }, extra_repeatable => { b => 1 } },              subfield => { extra => { a => 1 }, extra_repeatable => { b => 1 } },
# Line 181  $expected_error, 'validate without subfi Line 180  $expected_error, 'validate without subfi
180    
181  ok(my $r1 = $v->report, 'report');  ok(my $r1 = $v->report, 'report');
182    
183    diag "report: $r1" if ( $debug );
184    
185  is_deeply(  is_deeply(
186          test_v({          test_v({
187                  '900' => 'foo',                  '900' => 'foo',
# Line 192  is_deeply( Line 193  is_deeply(
193          }, undef),          }, undef),
194  $expected_error, 'validate with subfields');  $expected_error, 'validate with subfields');
195    
   
196  ok(my $r2 = $v->report, 'report');  ok(my $r2 = $v->report, 'report');
197    
198  cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');  cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');

Legend:
Removed from v.857  
changed lines
  Added in v.949

  ViewVC Help
Powered by ViewVC 1.1.26