Newer
Older
NetAddr-IP / Lite / t / v4-old-first.t
@Luis Muñoz Luis Muñoz on 21 Oct 2014 840 bytes Import of LUISMUNOZ/NetAddr-IP-4.001 from CPAN.
  1. use NetAddr::IP::Lite qw(:old_nth);
  2.  
  3. my $nets = {
  4. '10.0.0.16' => [ 24, '10.0.0.1', '10.0.0.254', '10.0.0.10'],
  5. '10.0.0.5' => [ 30, '10.0.0.5', '10.0.0.6', 'undef' ],
  6. '10.128.0.1' => [ 8, '10.0.0.1', '10.255.255.254', '10.0.0.10'],
  7. '10.128.0.1' => [ 24, '10.128.0.1', '10.128.0.254', '10.128.0.10'],
  8. };
  9.  
  10. $| = 1;
  11. print "1..", (3 * scalar keys %$nets), "\n";
  12.  
  13. my $count = 1;
  14.  
  15. for my $a (keys %$nets) {
  16. my $ip = new NetAddr::IP::Lite $a, $nets->{$a}->[0];
  17. print '', (($ip->first->addr ne $nets->{$a}->[1] ?
  18. 'not ' : ''),
  19. "ok ", $count++, "\n");
  20. print '', (($ip->last->addr ne $nets->{$a}->[2] ?
  21. 'not ' : ''),
  22. "ok ", $count++, "\n");
  23.  
  24. my $new = $ip->nth(10);
  25. print '', (((defined $new ? $new->addr : 'undef') ne $nets->{$a}->[3] ?
  26. 'not ' : ''),
  27. "ok ", $count++, "\n");
  28. }
  29.  
  30.