File: 22-hostname.t

package info (click to toggle)
libvalidation-class-perl 7.900057-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,572 kB
  • ctags: 355
  • sloc: perl: 21,493; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 985 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use Test::More;

package main;

use utf8;
use Validation::Class::Simple;

my $s = Validation::Class::Simple->new(
    fields => {
        domain_name => {hostname => 1}
    }
);

sub should_fail {
    my ($name, @domains) = @_;
    for (@domains) {
        $s->params->{$name} = $_;
        ok !$s->validate($name), "$_ is an invalid $name param";
    }
}

sub should_pass {
    my ($name, @domains) = @_;
    for (@domains) {
        $s->params->{$name} = $_;
        ok $s->validate($name), "$_ is a valid $name param";
    }
}

# failures

diag 'validating bad hostnames';
should_fail 'domain_name' => (
    '.example.com',
    'Abc.example.',
    'Abc..example.com',
    'A~b~c~example.com',
    'a#b[j\k]example.com',
    'just"not"right.example.com',
    'this!is.example.com',
    'this is.example.com',
    'this\ still\"not\\allowed.example.com',
);

diag 'validating good hostnames';
should_pass 'domain_name' => qw(
    example.com
    cpan.org
    us.gov
);

done_testing;