Newer
Older
NetAddr-IP / Lite / Util / t / packzeros.t
@Michael Robinton Michael Robinton on 21 Oct 2014 1 KB Import of MIKER/NetAddr-IP-4.049 from CPAN.
  1. # Before `make install' is performed this script should be runnable with
  2. # `make test'. After `make install' it should work as `perl test.pl'
  3.  
  4. ######################### We start with some black magic to print on failure.
  5. # Change 1..1 below to 1..last_test_to_print .
  6. # (It may become useful if the test is moved to ./t subdirectory.)
  7.  
  8. BEGIN { $| = 1; print "1..13\n"; }
  9. END {print "not ok 1\n" unless $loaded;}
  10.  
  11. use NetAddr::IP::Util qw(
  12. packzeros
  13. );
  14.  
  15. $loaded = 1;
  16. print "ok 1\n";
  17. ######################### End of black magic.
  18.  
  19. # Insert your test code below (better if it prints "ok 13"
  20. # (correspondingly "not ok 13") depending on the success of chunk 13
  21. # of the test code):
  22.  
  23. $test = 2;
  24.  
  25. sub ok {
  26. print "ok $test\n";
  27. ++$test;
  28. }
  29.  
  30. my @addr = qw # input expected
  31. ( D0:00:0000:0000:000:b00:0000:000 d0::b00:0:0
  32. 0d0:00:0000:0000:000:0B00:: d0::b00:0:0
  33. ::c3D4:e5d6:0:0:0:0 0:0:c3d4:e5d6::
  34. 0:0000:c3D4:e5d6:0:0:0:0 0:0:c3d4:e5d6::
  35. 0:0:0:0:0:0:0:0 ::
  36. 0:0:: ::
  37. ::0:000:0 ::
  38. 0:0::1.2.3.4 ::1.2.3.4
  39. ::1.2.3.4 ::1.2.3.4
  40. ::01b2:C3d4:0:0:0:1.2.3.4 0:1b2:c3d4::1.2.3.4
  41. 0:0:0:0:a1b2:c3D4:: ::a1b2:c3d4:0:0
  42. 12:0:0:0:34:0:00:000 12::34:0:0:0
  43. );
  44.  
  45. for(my $i=0;$i<@addr;$i+=2) {
  46. my $addr = $addr[$i];
  47. my $rv = packzeros($addr);
  48. my $exp = lc $addr[$i +1];
  49. print "got: $rv\nexp: $exp\nnot "
  50. unless $rv eq $exp;
  51. &ok;
  52. }