Newer
Older
NetAddr-IP / Lite / t / contains.t
@Luis Muñoz Luis Muñoz on 21 Oct 2014 614 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..12\n";
  8.  
  9. my $test = 1;
  10. sub ok() {
  11. print 'ok ',$test++,"\n";
  12. }
  13.  
  14. my $net4 = NetAddr::IP::Lite->new('1.2.3.5/30');
  15. my $net6 = NetAddr::IP::Lite->new('FF::85/126');
  16. my @try = qw(
  17. 1.2.3.3 0
  18. 1.2.3.4 1
  19. 1.2.3.5 1
  20. 1.2.3.6 1
  21. 1.2.3.7 1
  22. 1.2.3.8 0
  23. FF::83 0
  24. FF::84 1
  25. FF::85 1
  26. FF::86 1
  27. FF::87 1
  28. FF::88 0
  29. );
  30. for (my $i=0;$i<@try;$i+=2) {
  31. my $ip = NetAddr::IP::Lite->new($try[$i]);
  32. my $rv = ($try[$i] =~ /:/)
  33. ? $net6->contains($ip)
  34. : $net4->contains($ip);
  35. print "got: $rv, exp: $try[$i+1]\nnot "
  36. unless $rv == $try[$i+1];
  37. &ok;
  38. }
  39.