/[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 653 by dpavlin, Thu Sep 7 15:57:48 2006 UTC revision 659 by dpavlin, Fri Sep 8 14:35:31 2006 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 => 29;  use Test::More tests => 50;
5  use Test::Exception;  use Test::Exception;
6  use blib;  use blib;
7    
# Line 30  is_deeply( $v->{rules}, { Line 30  is_deeply( $v->{rules}, {
30          '901' => [ 'a' ],          '901' => [ 'a' ],
31          '902' => [ 'b', 'c' ],          '902' => [ 'b', 'c' ],
32          '903' => [ 'a', 'b', 'c' ],          '903' => [ 'a', 'b', 'c' ],
33            '904' => [ 'a' ],
34            '905' => [ 'a*' ],
35  }, 'rules parsed');  }, 'rules parsed');
36    
37    
38    
39  throws_ok { $v->validate_errors() } qr/rec/, "validate_rec need rec";  throws_ok { $v->validate_errors() } qr/rec/, "validate_rec need rec";
40    
41  sub test_v {  sub test_v {
# Line 52  sub test_v { Line 56  sub test_v {
56                          my $k = shift @_;                          my $k = shift @_;
57                          ok($tmp = $tmp->{$k}, "found $k");                          ok($tmp = $tmp->{$k}, "found $k");
58                  }                  }
59                  diag "additional message: $tmp" if ($tmp);                  diag "tmp: ",dump($tmp) if ($debug);
60                    if ($tmp) {
61                            if (ref($tmp) eq 'HASH') {
62                                    return $tmp;
63                            } else {
64                                    diag "explanation: $tmp";
65                            }
66                    }
67          } else {          } else {
68                  ok(! $e, "validated $d");                  ok(! $e, "validated $d");
69                  diag "expected error: ", dump($e) if($e);                  diag "expected error: ", dump($e) if($e);
# Line 78  test_v({ Line 89  test_v({
89    
90  test_v({  test_v({
91          '901' => [ { 'b' => 42 } ]          '901' => [ { 'b' => 42 } ]
92  }, qw/field 901 subfield b/);  }, qw/field 901 subfield extra b/);
93    
94  test_v({  test_v({
95          '902' => [ { 'b' => 1 }, { 'c' => 2 } ]          '902' => [ { 'b' => 1 }, { 'c' => 2 } ]
# Line 86  test_v({ Line 97  test_v({
97    
98  test_v({  test_v({
99          '902' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]          '902' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]
100  }, qw/field 902 subfield a/);  }, qw/field 902 subfield extra a/);
101    
102  test_v({  test_v({
103          '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]          '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]
# Line 94  test_v({ Line 105  test_v({
105    
106  test_v({  test_v({
107          '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 }, { 'd' => 3 } ]          '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 }, { 'd' => 3 } ]
108  }, qw/field 903 subfield d/);  }, qw/field 903 subfield extra d/);
109    
110    is_deeply(
111    
112    test_v({
113            '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 }, { 'd' => 3 }, { 'e' => 4 } ]
114    }, qw/field 903 subfield extra/),
115    
116    { 'd' => 1, 'e' => 1 }, 'additional fields d, e');
117    
118    test_v({
119            '904' => [ { 'a' => 1, } ]
120    });
121    
122    test_v({
123            '904' => [ { 'b' => 1 } ]
124    }, qw/field 904 subfield extra b/);
125    
126    test_v({
127            '904' => [ { 'a' => [ 1,2 ] } ]
128    }, qw/field 904 subfield extra_repeatable a/);
129    
130    test_v({
131            '905' => [ { 'a' => [ 1,2 ] } ]
132    });
133    
134    test_v({
135            '905' => [ ]
136    });

Legend:
Removed from v.653  
changed lines
  Added in v.659

  ViewVC Help
Powered by ViewVC 1.1.26