Newer
Older
NetAddr-IP / Lite / t / v6-inc.t
@Michael Robinton Michael Robinton on 21 Oct 2014 1 KB Import of MIKER/NetAddr-IP-4.020 from CPAN.
  1. use Test::More;
  2. use NetAddr::IP::Lite;
  3.  
  4. # Test ++ in IPv6 addresses (Bug rt.cpan.org #7070 by a guest)
  5.  
  6. @ip = (NetAddr::IP::Lite->new('2001:468:ff:fffe::2/64'),
  7. NetAddr::IP::Lite->new('2001:468:ff:fffe::2/64'),
  8. NetAddr::IP::Lite->new('2001:468:ff:fffe::2/64'));
  9.  
  10. $ip[1] ++;
  11. $ip[2] ++; $ip[2] ++;
  12.  
  13. plan tests => 11;
  14.  
  15. # Test correct v6 creation
  16. isa_ok($_, 'NetAddr::IP::Lite') for @ip;
  17.  
  18. # Test that we did actually do something
  19. diag "$ip[0] -- $ip[1]"
  20. unless ok($ip[0] != $ip[1], "Auto incremented once differ");
  21. diag "$ip[0] -- $ip[2]"
  22. unless ok($ip[0] != $ip[2], "Auto incremented twice differ");
  23. diag "$ip[1] -- $ip[2]"
  24. unless ok($ip[1] != $ip[2], "Auto incremented two times differ");
  25.  
  26. # Test that what we did is correct
  27. is($ip[1], $ip[0] + 1, "Test of first auto-increment");
  28. is($ip[2], $ip[0] + 2, "Test of second auto-increment");
  29.  
  30. # Now test auto-decrement
  31.  
  32. $ip[1] --;
  33. $ip[2] --; $ip[2] --;
  34.  
  35. is($ip[0], $ip[1], "Decrement of decrement once is ok");
  36. is($ip[0], $ip[2], "Decrement of decrement twice is ok");
  37. is($ip[1], $ip[2], "Third case");
  38.