Newer
Older
NetAddr-IP / Lite / t / network.t
@Luis Muñoz Luis Muñoz on 21 Oct 2014 885 bytes Import of LUISMUNOZ/NetAddr-IP-4.001 from CPAN.
  1.  
  2. #use diagnostics;
  3. use NetAddr::IP::Lite;
  4.  
  5. $| = 1;
  6.  
  7. print "1..4\n";
  8.  
  9. my $test = 1;
  10. sub ok() {
  11. print 'ok ',$test++,"\n";
  12. }
  13.  
  14. my $loip = new NetAddr::IP::Lite('::1.2.3.4/120'); # same as 1.2.3.4/24
  15. my $hiip = new NetAddr::IP::Lite('FF00::1:4/120');
  16. my $dqip = new NetAddr::IP::Lite('1.2.3.4/24');
  17.  
  18. ## test '""' just for the heck of it
  19. my $exp = 'FF00:0:0:0:0:0:1:4/120';
  20. my $txt = sprintf("%s",$hiip);
  21. print 'got: ',$txt," exp: $exp\nnot "
  22. unless $txt eq $exp;
  23. &ok;
  24.  
  25. ## test network dq
  26. $exp = '1.2.3.0/24';
  27. my $net = $dqip->network;
  28. print 'got: ',$net, " exp: $exp\nnot "
  29. unless $net eq $exp;
  30. &ok;
  31.  
  32. ## test network hi
  33. $exp = 'FF00:0:0:0:0:0:1:0/120';
  34. $net = $hiip->network;
  35. print 'got: ',$net, " exp: $exp\nnot "
  36. unless $net eq $exp;
  37. &ok;
  38.  
  39. ## test network lo
  40. $exp = '0:0:0:0:0:0:102:300/120';
  41. $net = $loip->network;
  42. print 'got: ',$net, " exp: $exp\nnot "
  43. unless $net eq $exp;
  44. &ok;