Newer
Older
NetAddr-IP / Lite / t / old-nth.t
@Luis Muñoz Luis Muñoz on 21 Oct 2014 493 bytes Import of LUISMUNOZ/NetAddr-IP-4.001 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. for (my $i=0;$i<@try;$i+=2) {
  28. my $rv = $ip4->nth($try[$i]);
  29. $rv = defined $rv
  30. ? $rv->addr
  31. : 'undef';
  32. print "got: $rv, exp: $try[$i+1]\nnot "
  33. unless $rv eq $try[$i+1];
  34. &ok;
  35. }