File: 05-length.t

package info (click to toggle)
libvalidation-class-perl 7.900057-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,616 kB
  • sloc: perl: 21,493; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 638 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
use Test::More tests => 5;

package MyVal;
use Validation::Class;

package main;

my $r = MyVal->new(
    fields => {foobar => {length => '1'}},
    params => {foobar => 'a'}
);

ok $r->validate(), 'foobar validates';
$r->params->{foobar} = 'abc';

ok !$r->validate(), 'foobar doesnt validate';
ok $r->errors_to_string()
  =~ /should be exactly 1 characters/,
  'displays proper error message';

$r->params->{foobar} = 'a';
$r->fields->{foobar}->{length} = 2;

ok !$r->validate(), 'foobar doesnt validate';
ok $r->errors_to_string()
  =~ /should be exactly 2 characters/,
  'displays proper error message';

#warn $r->errors_to_string();