Newer
Older
NetAddr-IP / Lite / t / loops.t
@Michael Robinton Michael Robinton on 21 Oct 2014 739 bytes Import of MIKER/NetAddr-IP-4.020 from CPAN.
  1. use NetAddr::IP::Lite;
  2.  
  3. $| = 1;
  4.  
  5. my @deltas = (0, 1, 2, 3, 255);
  6.  
  7. print "1..", 15 + @deltas, "\n";
  8.  
  9. my $count = 1;
  10.  
  11. for (my $ip = new NetAddr::IP::Lite '10.0.0.1/28';
  12. $ip < $ip->broadcast;
  13. $ip ++)
  14. {
  15. my $o = $ip->addr;
  16.  
  17. $o =~ s/^.+\.(\d+)$/$1/;
  18.  
  19. if ($o == $count) {
  20. print "ok $count\n";
  21. }
  22. else {
  23. print "not ok $count\n";
  24. }
  25.  
  26. ++ $count;
  27. }
  28.  
  29. my $ip = new NetAddr::IP::Lite '10.0.0.255/24';
  30. $ip ++;
  31.  
  32. if ($ip eq '10.0.0.0/24') {
  33. print "ok $count\n";
  34. }
  35. else {
  36. print "not ok $count\n";
  37. }
  38.  
  39. ++$count;
  40.  
  41. $ip = new NetAddr::IP::Lite '10.0.0.0/24';
  42.  
  43. for my $v (@deltas) {
  44. if ($ip + $v eq '10.0.0.' . $v . '/24') {
  45. print "ok $count\n";
  46. }
  47. else {
  48. print "not ok $count\n";
  49. }
  50. ++ $count;
  51. }