Newer
Older
NetAddr-IP / Lite / t / v4-num.t
@Michael Robinton Michael Robinton on 21 Oct 2014 753 bytes Import of MIKER/NetAddr-IP-4.042 from CPAN.
  1. use NetAddr::IP::Lite;
  2.  
  3. my $nets = {
  4. '10.1.2.3' => [ 32, 0 ],
  5. '10.2.3.4' => [ 31, 1 ],
  6. '10.0.0.16' => [ 24, 255 ],
  7. '10.128.0.1' => [ 8, 2 ** 24 - 1 ],
  8. '10.0.0.5' => [ 30, 3 ],
  9. };
  10.  
  11. my $new = 1; # flag for old vs new numeric returns
  12.  
  13. $| = 1;
  14.  
  15. $test = keys %$nets;
  16. $test *= 2;
  17. print "1..", $test, "\n";
  18.  
  19. $test = 1;
  20. sub tst {
  21. for my $a (keys %$nets) {
  22. my $nc = $nets->{$a}->[1] - $new; # net count
  23. $nc = 1 if $nc < 0;
  24. $nc = 2 if $new && $nets->{$a}->[0] == 31; # special case for /31, /127
  25. my $ip = new NetAddr::IP::Lite $a, $nets->{$a}->[0];
  26. print "got: $_, exp: $nc\nnot "
  27. unless ($_ = $ip->num) == $nc;
  28. print "ok ", $test++, "\n";
  29. }
  30. }
  31.  
  32. tst();
  33.  
  34. import NetAddr::IP::Lite qw(:old_nth);
  35. $new = 0;
  36. tst();