File: loops.t

package info (click to toggle)
libnetaddr-ip-perl 4.028%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,048 kB
  • ctags: 101
  • sloc: perl: 850; ansic: 90; pascal: 78; sh: 48; makefile: 8
file content (51 lines) | stat: -rw-r--r-- 739 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
use NetAddr::IP::Lite;

$| = 1;

my @deltas = (0, 1, 2, 3, 255);

print "1..", 15 + @deltas, "\n";

my $count = 1;

for (my $ip = new NetAddr::IP::Lite '10.0.0.1/28';
     $ip < $ip->broadcast;
     $ip ++)
{
    my $o = $ip->addr;

    $o =~ s/^.+\.(\d+)$/$1/;

    if ($o == $count) {
	print "ok $count\n";
    }
    else {
	print "not ok $count\n";
    }

    ++ $count;
}

my $ip = new NetAddr::IP::Lite '10.0.0.255/24';
$ip ++;

if ($ip eq '10.0.0.0/24') {
    print "ok $count\n";
}
else {
    print "not ok $count\n";
}

++$count;

$ip = new NetAddr::IP::Lite '10.0.0.0/24';

for my $v (@deltas) {
    if ($ip + $v eq '10.0.0.' . $v . '/24') {
	print "ok $count\n";
    }
    else {
	print "not ok $count\n";
    }
    ++ $count;
}