Net-IPAddress-Util

 view release on metacpan or  search on metacpan

t/10-ip-address.t  view on Meta::CPAN

#!/usr/bin/env perl

BEGIN {
  if ($] ge '5.012') {
    use strict;
    use warnings;
  }
}

use lib '.';
use Net::IPAddress::Util qw( :constr );
use Net::IPAddress::Util::Range;
use Net::IPAddress::Util::Collection;
use Test::More tests => 49;

$Net::IPAddress::Util::DIE_ON_ERROR = 1;
$Net::IPAddress::Util::PROMOTE_N32 = 0;

{
  # diag('Pure IPv4');
  my $test = IP('192.168.0.1');
  my $nf = $test->normal_form();
  is($test->str() ,        '192.168.0.1', "Pure IPv4 round-trip via str()");
  is("$test"      ,        '192.168.0.1', "Pure IPv4 round-trip overloaded");
  is($test->ipv4(),        '192.168.0.1', "Pure IPv4 round-trip via ipv4()");
  is($test->ipv6(), '::ffff:192.168.0.1', "Pure IPv4 round-trip via ipv6()");
  is($nf          , '00000000000000000000ffffc0a80001', "Pure IPv4 round-trip normal form");
  is($test->as_n32(), '3232235521', "Pure IPv4 round-trip via as_n32()");
  is($test->as_n128(), '281473913978881', "Pure IPv4 round-trip via as_n128()");
}

{
  # diag('Pure IPv4 the other way around');
  my $test = IP('281473913978881');
  my $nf = $test->normal_form();
  is("$test"      ,        '192.168.0.1', "Pure IPv4 the other way around round-trip overloaded");
  is($nf          , '00000000000000000000ffffc0a80001', "Pure IPv4 the other way around round-trip normal form");
}

{
  # diag('IPv4-in-IPv6');
  my $test = IP('::ffff:192.168.0.1');
  my $nf = $test->normal_form();
  is("$test" , '192.168.0.1', "IPv4-in-IPv6 round-trip");
  is($nf , '00000000000000000000ffffc0a80001', "IPv4-in-IPv6 round-trip normal form");
}

{
  # diag('IPv4-as-IPv6');
  my $test = IP('::ffff:c0a8:1');
  my $nf = $test->normal_form();
  is("$test" , '192.168.0.1', "IPv4-as-IPv6 round-trip");
  is($nf , '00000000000000000000ffffc0a80001', "IPv4-as-IPv6 round-trip normal form");
}

{
  # diag('Pure IPv6');
  my $test = IP('12::34');
  my $nf = $test->normal_form();
  is("$test" , '12::34', "Pure IPv6 round-trip");
  is($nf , '00120000000000000000000000000034', "Pure IPv6 round-trip normal form");
}

{



( run in 2.070 seconds using v1.01-cache-2.11-cpan-364913b4093 )