Newer
Older
NetAddr-IP / Lite / t / old-nth.t
@Michael Robinton Michael Robinton on 21 Oct 2014 492 bytes Import of MIKER/NetAddr-IP-4.020 from CPAN.
  1.  
  2. #use diagnostics;
  3. use NetAddr::IP::Lite qw(:old_nth);
  4.  
  5. $| = 1;
  6.  
  7. print "1..9\n";
  8.  
  9. my $test = 1;
  10. sub ok() {
  11. print 'ok ',$test++,"\n";
  12. }
  13.  
  14. my $ip4 = NetAddr::IP::Lite->new('1.2.3.11/29');
  15.  
  16. my @try = qw(
  17. 0 undef
  18. 1 1.2.3.9
  19. 2 1.2.3.10
  20. 3 1.2.3.11
  21. 4 1.2.3.12
  22. 5 1.2.3.13
  23. 6 1.2.3.14
  24. 7 1.2.3.15
  25. 8 undef
  26. );
  27.  
  28. for (my $i=0;$i<@try;$i+=2) {
  29. my $rv = $ip4->nth($try[$i]);
  30. $rv = defined $rv
  31. ? $rv->addr
  32. : 'undef';
  33. print "got: $rv, exp: $try[$i+1]\nnot "
  34. unless $rv eq $try[$i+1];
  35. &ok;
  36. }