]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/1_validate_13_html_file.t
add PSGI handler
[chaz/p5-CGI-Ex] / t / 1_validate_13_html_file.t
1 # -*- Mode: Perl; -*-
2
3 use strict;
4
5 $^W = 1;
6
7 ### determine number of tests
8 seek(DATA,0,0);
9 my $prog = join "", <DATA>;
10 my @tests = ($prog =~ /&print_ok\(/g);
11 my $tests = @tests;
12 print "1..$tests\n";
13
14 require CGI::Ex::Validate;
15
16 my ($N, $v, $e, $ok) = (0);
17
18 sub validate {
19 return scalar &CGI::Ex::Validate::validate(@_);
20 }
21 sub print_ok {
22 my $ok = shift;
23 $N ++;
24 warn "Test failed at line ".(caller)[2]."\n" if ! $ok;
25 print "" . ($ok ? "" : "not ") . "ok $N\n";
26 }
27 &print_ok(1);
28
29 ###----------------------------------------------------------------###
30
31 ### where are my samples
32 my $dir = __FILE__;
33 $dir =~ tr|\\|/|; # should probably use File::Spec
34 $dir =~ s|[^/]+$|samples| || die "Couldn't determine dir";
35 $dir =~ s|^t/|./t/|; # to satisfy conf
36
37 ### single group
38 $v = "$dir/html1.htm";
39
40 $e = &validate({}, $v);
41 &print_ok($e);
42 $e = &validate({user => 1}, $v);
43 &print_ok(! $e);
44 $e = &validate({user => 1, bar => 1}, $v);
45 &print_ok($e);
46 $e = &validate({user => 1, bar => 1, foo => 1}, $v);
47 &print_ok(! $e);
48
49
50 ### three groups, some with validate_if's - using arrayref
51 $v = "$dir/html2.htm";
52
53 $e = &validate({}, $v);
54 &print_ok($e);
55 $e = &validate({user => 1}, $v);
56 &print_ok(! $e);
57 $e = &validate({user => 1, bar => 1}, $v);
58 &print_ok($e);
59 $e = &validate({user => 1, bar => 1, foo => 1}, $v);
60 &print_ok(! $e);
61
62 __DATA__
This page took 0.030744 seconds and 4 git commands to generate.