File: Catmandu-Validator-Simple.t

package info (click to toggle)
libcatmandu-perl 1.0304-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,756 kB
  • ctags: 695
  • sloc: perl: 13,756; makefile: 34
file content (35 lines) | stat: -rw-r--r-- 637 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
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;

my $pkg;

BEGIN {
    $pkg = 'Catmandu::Validator::Simple';
    use_ok $pkg;
}

require_ok $pkg;

my $v = Catmandu::Validator::Simple->new(
    handler => sub {
        $_[0]->{field} eq '1' ? undef : 'Not 1';
    }
);

can_ok $v, 'validate_data';

throws_ok {$v->new(handler => 1)} qr/handler should be a CODE reference/;

my $rec = {field => 1};

is $v->validate($rec), $rec, 'validate - success';

is $v->validate({field => 3}), undef, 'validate - fails';

is_deeply $v->last_errors, ['Not 1'], 'last_errors returns error message';

done_testing 7;