File: 25_results.t

package info (click to toggle)
libdata-formvalidator-perl 4.66-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 588 kB
  • ctags: 127
  • sloc: perl: 2,756; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use Test::More tests => 7;

use Data::FormValidator; 

my %FORM = (
	stick  => 'big',
	speak  => 'softly',
    mv     => ['first','second'],  
);

my $results = Data::FormValidator->check(\%FORM, 
    { 
        required => [ 'stick', 'fromsub', 'whoami' ],
        optional => ['mv', 'opt_1', 'opt_2', ],
        defaults => {
            fromsub  => sub { return "got value from a subroutine"; },
        },
        defaults_regexp_map => {
            qr/^opt_/ => 2,
        },
    }
);

ok($results->valid('stick') eq 'big','using check() as class method');
is($results->valid('stick'),$FORM{stick}, 'valid() returns single value in scalar context');
my @mv = $results->valid('mv');
is_deeply(\@mv,$FORM{mv}, 'valid() returns multi-valued results');
my @stick = $results->valid('stick');
is_deeply(\@stick,[ $FORM{stick} ], 'valid() returns single value in array context');
ok($results->valid('fromsub') eq "got value from a subroutine", 'usg CODE references as default values');

{
    is( $results->valid('opt_1'), 2, "defaults_regexp works (case 1)");
    is( $results->valid('opt_2'), 2, "defaults_regexp works (case 1)");

}