Newer
Older
NetAddr-IP / Lite / t / v4-last.t
@Luis Muñoz Luis Muñoz on 21 Oct 2014 682 bytes Import of LUISMUNOZ/NetAddr-IP-4.001 from CPAN.
  1. use NetAddr::IP::Lite;
  2.  
  3. my %w = ('default' => [ '255.255.255.254', '0.0.0.0' ],
  4. 'loopback' => [ '127.255.255.254', '255.0.0.0' ],
  5. '127.0.0.1/8' => [ '127.255.255.254', '255.0.0.0' ],
  6. '10.' => [ '10.255.255.254', '255.0.0.0' ],
  7. '10.10.10/24' => [ '10.10.10.254', '255.255.255.0' ],
  8. );
  9.  
  10. $| = 1;
  11.  
  12. print '1..', (2 * scalar keys %w), "\n";
  13.  
  14. my $count = 1;
  15.  
  16. for my $a (keys %w) {
  17. my $ip = NetAddr::IP::Lite->new($a)->last;
  18.  
  19. if ($ip->addr eq $w{$a}->[0]) {
  20. print "ok ", $count++, "\n";
  21. }
  22. else {
  23. print "not ok ", $count++, "\n";
  24. }
  25.  
  26. if ($ip->mask eq $w{$a}->[1]) {
  27. print "ok ", $count++, "\n";
  28. }
  29. else {
  30. print "not ok ", $count++, "\n";
  31. }
  32. }