| 1 | 1 | ▶ | use NetAddr::IP::Lite; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | *_no_octal = \&NetAddr::IP::Lite::_no_octal; | |
| 3 | |||
| 4 | 1 | ▶ | use Test::More; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | my @ranges = ( | |
| 7 | [ '10.0.0.0/8', '10.0.0.0', '10.255.255.255' ], | ||
| 8 | [ '192.68.0.0/16', '192.068.0.0', '192.068.255.255' ], | ||
| 9 | ); | ||
| 10 | |||
| 11 | 1 | my @weird = ( | |
| 12 | [ '128.111.12.0', '128.111.12.129' ], | ||
| 13 | ); | ||
| 14 | |||
| 15 | 1 | plan tests => 6 * @ranges + 2 * @weird + 28; | |
| 16 | |||
| 17 | 1 | for my $r (@ranges) { | |
| 18 | 2 | my $r1 = new_no NetAddr::IP::Lite $r->[1] . '-' . $r->[2]; | |
| 19 | 2 | isa_ok($r1, 'NetAddr::IP::Lite'); | |
| 20 | 2 | is($r1, $r->[0], "Correct interpretation (with space)"); | |
| 21 | |||
| 22 | 2 | $r1 = new_no NetAddr::IP::Lite $r->[1] . ' - ' . $r->[2]; | |
| 23 | 2 | isa_ok($r1, 'NetAddr::IP::Lite'); | |
| 24 | 2 | is($r1, $r->[0], "Correct interpretation (w/o space)"); | |
| 25 | |||
| 26 | 2 | $r1 = new_no NetAddr::IP::Lite $r->[0]; | |
| 27 | 2 | isa_ok($r1, 'NetAddr::IP::Lite'); | |
| 28 | 2 | my @rev = (undef,_no_octal($r->[1]),_no_octal($r->[2])); | |
| 29 | 2 | is($r1->range, $rev[1] . ' - ' . $rev[2], "Correct reverse"); | |
| 30 | } | ||
| 31 | |||
| 32 | 1 | for my $r (@weird) | |
| 33 | { | ||
| 34 | 1 | my $r1 = new_no NetAddr::IP::Lite $r->[0] . '-' . $r->[1]; | |
| 35 | 1 | ok(! defined $r1, "Weird range w/o space produces undef"); | |
| 36 | 1 | $r1 = new_no NetAddr::IP::Lite $r->[0] . ' - ' . $r->[1]; | |
| 37 | 1 | ok(! defined $r1, "Weird range with space produces undef"); | |
| 38 | } | ||
| 39 | |||
| 40 | 1 | for my $o (254, 252, 248, 240, 224, 192, 128) | |
| 41 | { | ||
| 42 | 7 | my $r1 = new_no NetAddr::IP::Lite '0.0.0.0 - ' . $o . '.0.0.0'; | |
| 43 | 7 | ok(! defined $r1, "Weird $o range, first octet"); | |
| 44 | 7 | $r1 = new_no NetAddr::IP::Lite '0.0.0.0 - 0.' . $o . '.0.0'; | |
| 45 | 7 | ok(! defined $r1, "Weird $o range, second octet"); | |
| 46 | 7 | $r1 = new_no NetAddr::IP::Lite '0.0.0.0 - 0.0.' . $o . '.0'; | |
| 47 | 7 | ok(! defined $r1, "Weird $o range, third octet"); | |
| 48 | 7 | $r1 = new_no NetAddr::IP::Lite '0.0.0.0 - 0.0.0.' . $o; | |
| 49 | 7 | ok(! defined $r1, "Weird $o range, fourth octet"); | |
| 50 | } | ||