/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 515 - (show annotations)
Tue May 16 15:23:05 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1467 byte(s)
 r681@llin:  dpavlin | 2006-05-16 17:08:13 +0200
 added validate_errors which returs all validation errors for this record

1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More tests => 16;
5 use Test::Exception;
6 use blib;
7
8 use Data::Dumper;
9 use Cwd qw/abs_path/;
10
11 BEGIN {
12 use_ok( 'WebPAC::Validate' );
13 }
14
15 my $debug = shift @ARGV;
16
17 ok(my $abs_path = abs_path($0), "abs_path");
18 $abs_path =~ s#/[^/]*$#/#;
19
20 throws_ok { new WebPAC::Validate( no_log => 1 ) } qr/need path/, "new without path";
21
22 ok(my $v = new WebPAC::Validate(
23 path => "$abs_path/data/validate_test",
24 ), "new");
25
26 ok($v->{rules}, "rules exist");
27
28 is_deeply( $v->{rules}, {
29 '900' => 1,
30 '901' => [ 'a' ],
31 '902' => [ 'b', 'c' ],
32 '903' => [ 'a', 'b', 'c' ],
33 }, 'rules parsed');
34
35 throws_ok { $v->validate_errors() } qr/rec/, "validate_rec need rec";
36
37 ok($v->validate_errors({ '900' => 'foo' }), '900 garbage input');
38
39 ok(! $v->validate_errors({
40 '900' => [ qw/foo bar baz/ ]
41 }), '900 no sf');
42
43 ok($v->validate_errors({
44 '901' => [ qw/foo bar baz/ ]
45 }), '901 no sf');
46
47 ok(! $v->validate_errors({
48 '901' => [ { 'a' => 42 } ]
49 }), '901^a');
50
51 ok($v->validate_errors({
52 '901' => [ { 'b' => 42 } ]
53 }), '901^b');
54
55 ok(! $v->validate_errors({
56 '902' => [ { 'b' => 1 }, { 'c' => 2 } ]
57 }), '902^b 902^c');
58
59 ok($v->validate_errors({
60 '902' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]
61 }), '902^a 902^b 902^c');
62
63 ok(! $v->validate_errors({
64 '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 } ]
65 }), '903^a 903^b 903^c');
66
67 ok($v->validate_errors({
68 '903' => [ { 'a' => 0 }, { 'b' => 1 }, { 'c' => 2 }, { 'd' => 3 } ]
69 }), '903^a 903^b 903^c 903^d');

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26