File: 04_arrayify_undef.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 (34 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (5)
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
use strict;
$^W = 1;

use Test::More tests => 4;

{
    my $test_name = 
        "checks for correct behavior when 'required'
         is not specified; fails if _arrayify() does not return an empty list";

    use Data::FormValidator;
    my $input_profile = { optional => [ qw( email ) ] };
    my $validator = Data::FormValidator->new({default => $input_profile});

    my $input_hashref = {email => 'bob@example.com' };

    my ($valids, $missings, $invalids, $unknowns);
    eval{ ($valids, $missings, $invalids, $unknowns) = $validator->validate($input_hashref, 'default') };
    is($@, '', $test_name);
    is(@$missings, 0, $test_name);
}

{
    my $test_name = "arrayref with first element undef";
    use Data::FormValidator::Results;

    my $inputs = [ undef, 1, 2, 3, "Echo", "Foxtrot" ];
    my $retval = Data::FormValidator::Results::_arrayify($inputs);
    my @retval = Data::FormValidator::Results::_arrayify($inputs);

    is($retval, 6, "$test_name... in scalar context");
    is_deeply(\@retval, $inputs, "$test_name..in list context");

}