File: v4-re.t

package info (click to toggle)
libnetaddr-ip-perl 4.007%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 728 kB
  • ctags: 92
  • sloc: perl: 715; pascal: 78; ansic: 77; makefile: 56; sh: 23
file content (38 lines) | stat: -rw-r--r-- 827 bytes parent folder | download
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
use Test::More;

# $Id: v4-re.t,v 1.1.1.1 2006/08/14 15:36:06 lem Exp $

my @ips = qw!
    10.11.12.13
    10.11.12/24
    10.11.0/27
    !;

plan tests => 299;

die "# Cannot continue without NetAddr::IP\n"
    unless use_ok('NetAddr::IP');

my @addrs = map { new NetAddr::IP $_ } @ips;

for my $a (@addrs)
{
    isa_ok($a, 'NetAddr::IP');
    my $re = $a->re;
    my $rx;

    eval { $rx = qr/$re/ };
    diag "Compilation of the resulting regular expression failed: $@"
	unless ok(!$@, "Compilation of the resulting regular expression");

    for (my $ip = $a->network; 
	 $ip < $a->broadcast && $a->masklen != 32;
	 $ip ++)
    {
	ok($a->addr =~ m/$rx/, "Match of $ip in $a");
    }

    ok($a->broadcast->addr =~ m/$rx/, "Match of broadcast of $a");
    ok(NetAddr::IP->new('default') !~ m/$rx/, "0/0 does not match");
}