Newer
Older
NetAddr-IP / Lite / t / relops.t
  1. use NetAddr::IP::Lite;
  2.  
  3. BEGIN {
  4. @gt = (
  5. [ '255.255.255.255/32', '0.0.0.0/0' ],
  6. [ 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '::/0' ],
  7. [ '10.0.1.0/16', '10.0.0.1/24' ],
  8. [ '10.0.0.1/24', '10.0.0.0/24' ],
  9. [ 'deaf:beef::1/64', 'dead:beef::/64' ],
  10. );
  11.  
  12. @ngt = (
  13. [ '0.0.0.0/0', '255.255.255.255/32' ],
  14. [ '::/0', 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' ],
  15. [ '10.0.0.0/24', '10.0.0.0/24' ],
  16. [ 'dead:beef::/60', 'dead:beef::/60' ],
  17. );
  18.  
  19. @cmp = (
  20. [ '0.0.0.0/0', '255.255.255.255/32', -1 ],
  21. [ '::/0', 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', -1 ],
  22. [ '10.0.0.0/16', '10.0.0.0/8', 1 ],
  23. [ 'dead:beef::/60', 'dead:beef::/40', 1 ],
  24. [ '10.0.0.0/24', '10.0.0.0/8', 1 ],
  25. [ '255.255.255.255/32', '0.0.0.0/0', 1 ],
  26. [ 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '::/0', 1 ],
  27. [ '142.52.5.87', '142.52.2.88', 1 ],
  28. [ '10.0.0.0/24', '10.0.0.0/24', 0 ],
  29. [ 'default', 'default', 0 ],
  30. [ 'broadcast', 'broadcast', 0],
  31. [ 'loopback', 'loopback', 0],
  32. );
  33.  
  34. };
  35.  
  36. use Test::More tests => @gt + @ngt + (2 * @cmp);
  37.  
  38. for my $a (@gt) {
  39. $a_ip = new NetAddr::IP::Lite $a->[0];
  40. $b_ip = new NetAddr::IP::Lite $a->[1];
  41.  
  42. ok($a_ip > $b_ip, "$a_ip > $b_ip");
  43. }
  44.  
  45. for my $a (@ngt) {
  46. $a_ip = new NetAddr::IP::Lite $a->[0];
  47. $b_ip = new NetAddr::IP::Lite $a->[1];
  48.  
  49. ok(!($a_ip > $b_ip), "$a_ip !> $b_ip");
  50. }
  51.  
  52. for $a (@cmp) {
  53. $a_ip = new NetAddr::IP::Lite $a->[0];
  54. $b_ip = new NetAddr::IP::Lite $a->[1];
  55.  
  56. is($a_ip <=> $b_ip, $a->[2], "$a_ip <=> $b_ip is $a->[2]");
  57. is($a_ip cmp $b_ip, $a->[2], "$a_ip cmp $b_ip is $a->[2]");
  58. }
  59.