Newer
Older
NetAddr-IP / Lite / t / addr.t
@Luis Muñoz Luis Muñoz on 21 Oct 2014 715 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..3\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.  
  17. ## test '""' just for the heck of it
  18. my $exp = 'FF00:0:0:0:0:0:1:4/120';
  19. my $txt = sprintf("%s",$hiip);
  20. print 'got: ',$txt," exp: $exp\nnot "
  21. unless $txt eq $exp;
  22. &ok;
  23.  
  24. ## test addr lo
  25. $exp = '0:0:0:0:0:0:102:304';
  26. my $addr = $loip->addr;
  27. print "got: $addr, exp: $exp\nnot "
  28. unless $addr eq $exp && ! ref $addr;
  29. &ok;
  30.  
  31. ## test addr hi
  32. $exp = 'FF00:0:0:0:0:0:1:4';
  33. $addr = $hiip->addr;
  34. print "got: $addr, exp: $exp\nnot "
  35. unless $addr eq $exp && ! ref $addr;
  36. &ok;