File: relops.t

package info (click to toggle)
libnetaddr-ip-perl 4.079%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,568 kB
  • sloc: perl: 1,417; cpp: 67; makefile: 9
file content (59 lines) | stat: -rw-r--r-- 1,566 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
53
54
55
56
57
58
59
use NetAddr::IP;

BEGIN {
@gt = (
       [ '255.255.255.255/32', '0.0.0.0/0' ],
       [ 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '::/0' ],
       [ '10.0.1.0/16', '10.0.0.1/24' ],
       [ '10.0.0.1/24', '10.0.0.0/24' ],
       [ 'deaf:beef::1/64', 'dead:beef::/64' ],
       );

@ngt = (
	[ '0.0.0.0/0', '255.255.255.255/32' ],
	[ '::/0', 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' ],
	[ '10.0.0.0/24', '10.0.0.0/24' ],
	[ 'dead:beef::/60', 'dead:beef::/60' ],
	);

@cmp = (
	[ '0.0.0.0/0', '255.255.255.255/32', -1 ],
	[ '::/0', 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', -1 ],
	[ '10.0.0.0/16', '10.0.0.0/8', 1 ],
	[ 'dead:beef::/60', 'dead:beef::/40', 1 ],
	[ '10.0.0.0/24', '10.0.0.0/8', 1 ],
	[ '255.255.255.255/32', '0.0.0.0/0', 1 ],
	[ 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '::/0', 1 ],
	[ '142.52.5.87', '142.52.2.88', 1 ],
	[ '10.0.0.0/24', '10.0.0.0/24', 0 ],
	[ 'default', 'default', 0 ],
	[ 'broadcast', 'broadcast', 0],
	[ 'loopback', 'loopback', 0],
	);

};

use Test::More tests => @gt + @ngt + (2 * @cmp);

for my $a (@gt) {
    $a_ip = new NetAddr::IP::Lite $a->[0];
    $b_ip = new NetAddr::IP::Lite $a->[1];

    ok($a_ip > $b_ip, "$a_ip > $b_ip");
}

for my $a (@ngt) {
    $a_ip = new NetAddr::IP::Lite $a->[0];
    $b_ip = new NetAddr::IP::Lite $a->[1];

    ok(!($a_ip > $b_ip), "$a_ip !> $b_ip");
}

for $a (@cmp) {
    $a_ip = new NetAddr::IP::Lite $a->[0];
    $b_ip = new NetAddr::IP::Lite $a->[1];

    is($a_ip <=> $b_ip, $a->[2], "$a_ip <=> $b_ip is $a->[2]");
    is($a_ip cmp $b_ip, $a->[2], "$a_ip cmp $b_ip is $a->[2]");
}