Newer
Older
NetAddr-IP / Lite / t / numeric.t
@Michael Robinton Michael Robinton on 21 Oct 2014 781 bytes Import of MIKER/NetAddr-IP-4.020 from CPAN.
  1.  
  2. #use diagnostics;
  3. use NetAddr::IP::Lite;
  4.  
  5. $| = 1;
  6.  
  7. print "1..6\n";
  8.  
  9. my $test = 1;
  10. sub ok() {
  11. print 'ok ',$test++,"\n";
  12. }
  13.  
  14. my @tval = qw # IP bcd mask bcd
  15. ( 8000:0:0:0:0:0:0:1/112 170141183460469231731687303715884105729 340282366920938463463374607431768145920
  16. 1.2.3.4/24 16909060 4294967040
  17. );
  18.  
  19. for (my $i=0;$i < @tval;$i+=3) {
  20. my $nip = NetAddr::IP::Lite->new($tval[$i]);
  21. ## test scalar return
  22. my $sclr = $nip->numeric;
  23. print "got: $sclr\nexp: $tval[$i+1]\nnot "
  24. unless $sclr .'x' eq $tval[$i+1] .'x';
  25. &ok;
  26.  
  27. ## test array return
  28. my($addr,$mask) = $nip->numeric;
  29. print "got: $addr\nexp: $tval[$i+1]\nnot "
  30. unless $addr .'x' eq $tval[$i+1] .'x';
  31. &ok;
  32.  
  33. print "got: $mask\nexp: $tval[$i+2]\nnot "
  34. unless $mask .'x' eq $tval[$i+2] .'x';
  35. &ok;
  36. }