File: constraint_regexp_map_profile_reuse.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 (43 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download | duplicates (6)
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
41
42
43
use Test::More (qw/no_plan/);
use Data::FormValidator;

my $profile = {
    required => [qw( test1 )],
    constraint_regexp_map => {
        qr/^test/ => 'email',
    },
};

my $data = {
    test1 => 'not an email',
};

my $results1 = Data::FormValidator->check($data, $profile);
my $c1 = {%{ $profile->{constraints} }};
my $results2 = Data::FormValidator->check($data, $profile);
my $c2 = {%{ $profile->{constraints} }};

is_deeply($results1->{profile},$results2->{profile}, "constraints aren't duped when profile with constraint_regexp_map is reused");
is_deeply($c1,$c2, "constraints aren't duped when profile with constraint_regexp_map is reused");

{
    my $profile = {
        required => [qw( test1 )],
        field_filter_regexp_map => {
            qr/^test/ => 'trim',
        },
    };

    my $data = {
        test1 => ' not an email ',
    };

    my $results1 = Data::FormValidator->check($data, $profile);
    my $c1 = {%{ $profile->{constraints} }};
    my $results2 = Data::FormValidator->check($data, $profile);
    my $c2 = {%{ $profile->{constraints} }};
    is_deeply($results1->{profile},$results2->{profile}, "field_filters aren't duped when profile with field_filter_regexp_map is reused");
    is_deeply($c1,$c2, "field_filters aren't duped when profile with field_filter_regexp_map is reused");

}