File: regexp_common.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 (71 lines) | stat: -rw-r--r-- 1,730 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Integration with Regexp::Common;

use Test::More tests => 10;

use Data::FormValidator; 

my %FORM = (
	bad_ip      => '127 0 0 1',
	good_ip     => '127.0.0.1',
    embedded_ip => 'The address is 127.0.0.1 or something close to that',
);

my $results;

eval {
$results = Data::FormValidator->check(\%FORM, { 
		required => [qw/good_ip bad_ip/],
		constraint_regexp_map => {
			qr/_ip$/ => 'RE_net_IPv4',

		}
	});
};
ok((not $@), 'runtime errors') or diag $@;
ok($results->valid->{good_ip}, 'good ip'); 
ok($results->invalid->{bad_ip}, 'bad ip'); 


$results = Data::FormValidator->check(\%FORM, { 
		untaint_all_constraints => 1,
		required => [qw/good_ip bad_ip/],
		constraint_regexp_map => {
			qr/_ip$/ => 'RE_net_IPv4',

		}
	});


ok((not $@), 'runtime errors') or diag $@;
ok($results->valid->{good_ip}, 'good ip with tainting');
ok($results->invalid->{bad_ip}, 'bad ip with tainting'); 

# Test passing flags
$results = Data::FormValidator->check(\%FORM, { 
		required => [qw/good_ip bad_ip/],
		constraint_regexp_map => {
			qr/_ip$/ => {
				constraint => 'RE_net_IPv4_dec',
				params => [ \'-sep'=> \' ' ],
			}
		}
	});


ok((not $@), 'runtime errors') or diag $@;
# Here we are trying passing a parameter which should reverse
# the notion of which one expect to succeed.
ok($results->valid->{bad_ip}, 'expecting success with params'); 
ok($results->invalid->{good_ip}, 'expecting failure with params'); 


# Testing end-to-end matching
$results = Data::FormValidator->check(\%FORM, { 
		required => [qw/embedded_ip/],
		constraint_regexp_map => {
			qr/_ip$/ =>  'RE_net_IPv4',
		}
	});
my $invalid = scalar $results->invalid || {};
ok($invalid->{embedded_ip}, 'testing that the RE must match from end-to-end');