File: 10-custom-validation.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 (35 lines) | stat: -rw-r--r-- 720 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
35
use Test::More tests => 5;

package MyVal;

use Validation::Class;

package main;

my $v = MyVal->new(
    fields => {
        foobar => {
            error      => 'foobar error',
            validation => sub {
                shift->{_ran_}++;
                return 1;
              }
        },
        barfoo => {
            required   => 1,
            validation => sub {
                return 0;
              }
        }
    },
    params => {
        foobar => 'abc123456',
        barfoo => 1
    }
);

ok $v, 'class initialized';
ok $v->validate('foobar'), 'valid';
ok $v->{_ran_} == 1, 'validation ran once as intended';
ok !$v->validate('barfoo'), 'not valid';
ok $v->errors_to_string, 'error message';