File: 19_refs_as_values.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 (40 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (7)
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
38
39
40
#!/usr/bin/perl -w

# This tests to make sure that we can use hashrefs and code refs as OK values in the input hash
# inspired by a patch from Boris Zentner

use lib ('.','../t');

$^W = 1;

use Test::More tests => 3;

use strict;
use Data::FormValidator;

my $input_profile =
{
  required => [ qw( arrayref hashref coderef ) ],
};

my $validator = new Data::FormValidator({default => $input_profile});

my $input_hashref = { 
	arrayref => ['', 1,2],
	hashref  => {tofu => 'good'},
	coderef  => sub { return 'the answer is 42' },
};

my ($valids, $missings, $invalids, $unknowns) = ({},[],[],[]);

($valids, $missings, $invalids, $unknowns) = $validator->validate($input_hashref, 'default');

# empty strings in arrays should be set to "undef"
ok(not defined $valids->{arrayref}->[0]);

# hash refs and code refs should be ok.
is(ref $valids->{hashref}, 'HASH');
is(ref $valids->{coderef}, 'CODE');