use Test::More; use NetAddr::IP qw(Exclude); my @r = ( ['10.0.0.0/8','10.0.0.0/9', [], ['10.128.0.0/9']], ['10.0.0.0/8','10.0.0.0/8', [], []], ['10.0.0.0/8','10.128.0.0/9', ['10.0.0.0/9'], []], ['10.0.0.0/8','10.128.0.0/10', ['10.0.0.0/9'], ['10.192.0.0/10']], ['10.0.0.0/8','10.0.0.0/32', [], ['10.0.0.1/32','10.0.0.2/31','10.0.0.4/30','10.0.0.8/29','10.0.0.16/28','10.0.0.32/27','10.0.0.64/26','10.0.0.128/25','10.0.1.0/24','10.0.2.0/23','10.0.4.0/22','10.0.8.0/21','10.0.16.0/20','10.0.32.0/19','10.0.64.0/18','10.0.128.0/17','10.1.0.0/16','10.2.0.0/15','10.4.0.0/14','10.8.0.0/13','10.16.0.0/12','10.32.0.0/11','10.64.0.0/10','10.128.0.0/9']], ['192.168.0.0/24','192.168.0.255/32',['192.168.0.0/25','192.168.0.128/26','192.168.0.192/27','192.168.0.224/28','192.168.0.240/29','192.168.0.248/30','192.168.0.252/31','192.168.0.254/32'],[]], ['192.168.0.0/23','192.168.0.127/32',['192.168.0.0/26','192.168.0.64/27','192.168.0.96/28','192.168.0.112/29','192.168.0.120/30','192.168.0.124/31','192.168.0.126/32'],['192.168.0.128/25','192.168.1.0/24']], ['1.2.3.4/32','1.2.3.4/32',[],[]], ['0.0.0.0/0','0.0.0.0/32',[],['0.0.0.1/32','0.0.0.2/31','0.0.0.4/30','0.0.0.8/29','0.0.0.16/28','0.0.0.32/27','0.0.0.64/26','0.0.0.128/25','0.0.1.0/24','0.0.2.0/23','0.0.4.0/22','0.0.8.0/21','0.0.16.0/20','0.0.32.0/19','0.0.64.0/18','0.0.128.0/17','0.1.0.0/16','0.2.0.0/15','0.4.0.0/14','0.8.0.0/13','0.16.0.0/12','0.32.0.0/11','0.64.0.0/10','0.128.0.0/9','1.0.0.0/8','2.0.0.0/7','4.0.0.0/6','8.0.0.0/5','16.0.0.0/4','32.0.0.0/3','64.0.0.0/2','128.0.0.0/1']], ['1.2.3.4/32','1.2.3.5/32',['1.2.3.4/32'],[]], ); plan tests => 4 * scalar @r; SKIP: { foreach my $case (@r) { my ($low, $up) = Exclude(NetAddr::IP->new($case->[0]), NetAddr::IP->new($case->[1])); my $ex_low = [map { NetAddr::IP->new($_) } @{$case->[2]}]; my $ex_up = [map { NetAddr::IP->new($_) } @{$case->[3]}]; is("@$up", "@$ex_up", "Upper half of Exclude($case->[0],$case->[1]) is @$ex_up"); is("@$low", "@$ex_low", "Lower half of Exclude($case->[0],$case->[1]) is @$ex_low"); ($low, $up) = NetAddr::IP->new($case->[0])->Exclude(NetAddr::IP->new($case->[1])); is("@$up", "@$ex_up", "Upper half of ($case->[0])->Exclude($case->[1]) is @$ex_up"); is("@$low", "@$ex_low", "Lower half of ($case->[0])->Exclude($case->[1]) is @$ex_low"); } }