/[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 768 by dpavlin, Fri Nov 3 19:41:28 2006 UTC revision 862 by dpavlin, Sun May 27 19:28:18 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Test::More tests => 47;  use Test::More tests => 54;
5  use Test::Exception;  use Test::Exception;
6  use blib;  use blib;
7    
# Line 17  my $debug = shift @ARGV; Line 17  my $debug = shift @ARGV;
17  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
18  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
19    
20  throws_ok { new WebPAC::Validate( no_log => 1 ) } qr/need path/, "new without path";  ok(my $v = new WebPAC::Validate(
21            debug => $debug,
22    ), "new witout path");
23    
24    ok( ! $v->{rules}, 'no path' );
25    
26  ok(my $v = new WebPAC::Validate(  ok(my $v = new WebPAC::Validate(
27          path => "$abs_path/data/validate_test",          path => "$abs_path/data/validate_test",
28          debug => $debug,          debug => $debug,
29  ), "new");  ), "new with path");
30    
31  ok($v->{rules}, "rules exist");  ok($v->{rules}, "rules exist");
32    
# Line 33  is_deeply( $v->{rules}, { Line 37  is_deeply( $v->{rules}, {
37          '903' => [ 'a', 'b', 'c' ],          '903' => [ 'a', 'b', 'c' ],
38          '904' => [ 'a' ],          '904' => [ 'a' ],
39          '905' => [ 'a*' ],          '905' => [ 'a*' ],
40    }, 'simple rules parsed');
41    
42    diag dump( $v ) if ( $debug );
43    
44    ok( $v->read_validate_file( "$abs_path/data/validate_test_simple" ), "read_validate_file" );
45    
46    diag dump( $v ) if ( $debug );
47    
48    ok($v->{rules}, "rules exist");
49    
50    is_deeply( $v->{rules}, {
51            '900' => [ 'a', 'b', 'c', 'd' ],
52  }, 'rules parsed');  }, 'rules parsed');
53    
54    ok( $v->read_validate_file( "$abs_path/data/validate_test" ), "read_validate_file" );
55    
56    is_deeply( $v->{rules}, {
57            '900' => 1,
58            '901' => [ 'a' ],
59            '902' => [ 'b', 'c' ],
60            '903' => [ 'a', 'b', 'c' ],
61            '904' => [ 'a' ],
62            '905' => [ 'a*' ],
63    }, 'rules');
64    
65    ok($v->{rules}, "rules exist");
66    
67  throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";  throws_ok { $v->validate_rec() } qr/rec/, "validate_rec need rec";
68    
# Line 46  sub test_v { Line 73  sub test_v {
73    
74          $row->{'000'} = [ 42 ];          $row->{'000'} = [ 42 ];
75    
76          $v->reset_errors;          $v->reset;
77          my $e = $v->validate_rec( $row );          my $e = $v->validate_rec( $row );
78    
79          diag "validate $d\n",dump($e) if ($debug);          diag "validate $d\n",dump($e) if ($debug);
# Line 162  $expected_error, 'validate without subfi Line 189  $expected_error, 'validate without subfi
189    
190  ok(my $r1 = $v->report, 'report');  ok(my $r1 = $v->report, 'report');
191    
192    diag "report: $r1" if ( $debug );
193    
194  is_deeply(  is_deeply(
195          test_v({          test_v({
196                  '900' => 'foo',                  '900' => 'foo',
# Line 173  is_deeply( Line 202  is_deeply(
202          }, undef),          }, undef),
203  $expected_error, 'validate with subfields');  $expected_error, 'validate with subfields');
204    
   
205  ok(my $r2 = $v->report, 'report');  ok(my $r2 = $v->report, 'report');
206    
207  cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');  cmp_ok($r1, 'eq', $r2, 'subfields same as non-subfields');

Legend:
Removed from v.768  
changed lines
  Added in v.862

  ViewVC Help
Powered by ViewVC 1.1.26