Subject: | Empty line is considered to be a correct value |
I'm expecting this test to pass:
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Data::FormValidator;
use Test::More tests => 4;
my $validate_rules = {
optional => [qw(
letter
letter_or_null
)],
constraint_methods => {
letter => qr/^[A-F]$/,
letter_or_null => qr/^(?:[A-F])?$/,
},
};
my $tests = [
{
block => {
letter => 'A',
},
status => 1
},
{
block => {
letter_or_null => 'A',
},
status => 1
},
{
block => {
letter => '',
},
status => 0
},
{
block => {
letter_or_null => '',
},
status => 1
},
];
foreach my $t (@{$tests}) {
my $results = Data::FormValidator->check($t->{block}, $validate_rules);
my $status;
if (
$results->has_invalid
or $results->has_missing
or $results->has_unknown
) {
$status = 0;
} else {
$status = 1;
}
my $msg = 'Block is ' . ($t->{status} ? 'valid' : 'invalid');
is ($status, $t->{status}, $msg);
}
__END__
The output of the test:
1..4
ok 1 - Block is valid
ok 2 - Block is valid
not ok 3 - Block is invalid
# Failed test 'Block is invalid'
# at a.pl line 63.
# got: '1'
# expected: '0'
ok 4 - Block is valid
# Looks like you failed 1 test of 4.