7 ### determine number of tests
9 my $prog = join "", <DATA>;
10 my @tests = ($prog =~ /&print_ok\(/g);
14 require CGI::Ex::Validate;
16 my ($N, $v, $e, $ok) = (0);
19 return scalar &CGI::Ex::Validate::validate(@_);
24 warn "Test failed at line ".(caller)[2]."\n" if ! $ok;
25 print "" . ($ok ? "" : "not ") . "ok $N\n";
29 ###----------------------------------------------------------------###
31 ### test single group for extra fields
34 'general no_extra_fields' => 'all',
35 foo => {max_len => 10},
39 $e = &validate({}, $v);
42 $e = &validate({foo => "foo"}, $v);
45 $e = &validate({foo => "foo", bar => "bar"}, $v);
48 $e = &validate({bar => "bar"}, $v);
52 ### test on failed validate if
55 'general no_extra_fields' => 'all',
56 'group validate_if' => 'baz',
57 foo => {max_len => 10},
61 $e = &validate({}, $v);
64 $e = &validate({foo => "foo"}, $v);
67 $e = &validate({foo => "foo", bar => "bar"}, $v);
70 $e = &validate({bar => "bar"}, $v);
73 ### test on successful validate if
76 'general no_extra_fields' => 'all',
77 'group validate_if' => 'baz',
78 foo => {max_len => 10},
79 baz => {max_len => 10},
83 $e = &validate({baz => 1}, $v);
86 $e = &validate({baz => 1, foo => "foo"}, $v);
89 $e = &validate({baz => 1, foo => "foo", bar => "bar"}, $v);
92 $e = &validate({baz => 1, bar => "bar"}, $v);
95 ### test on multiple groups, some with validate if
98 'general no_extra_fields' => 'all',
99 'group validate_if' => 'baz',
100 foo => {max_len => 10},
101 baz => {max_len => 10},
104 'group validate_if' => 'hem',
105 haw => {max_len => 10},
109 $e = &validate({haw => 1, baz => 1}, $v);
112 $e = &validate({haw => 1, baz => 1, foo => "foo"}, $v);
115 $e = &validate({haw => 1, baz => 1, foo => "foo", bar => "bar"}, $v);
118 $e = &validate({haw => 1, baz => 1, bar => "bar"}, $v);
122 ### test on multiple groups, some with validate if
125 'general no_extra_fields' => 'used',
126 'group validate_if' => 'baz',
127 foo => {max_len => 10},
128 baz => {max_len => 10},
131 'group validate_if' => 'hem',
132 haw => {max_len => 10},
136 $e = &validate({haw => 1, baz => 1}, $v);
139 $e = &validate({haw => 1, baz => 1, foo => "foo"}, $v);
142 $e = &validate({haw => 1, baz => 1, foo => "foo", bar => "bar"}, $v);
145 $e = &validate({haw => 1, baz => 1, bar => "bar"}, $v);