Net-IPAddress-Util
view release on metacpan or search on metacpan
t/15-siit-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')->SIIT();
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:0:192.168.0.1', "Pure IPv4 round-trip via ipv6()");
is($nf , '0000000000000000ffff0000c0a80001', "Pure IPv4 round-trip normal form");
is($test->as_n32(), '3232235521', "Pure IPv4 round-trip via as_n32()");
is($test->as_n128(), '18446462601965076481', "Pure IPv4 round-trip via as_n128()");
}
{
# diag('Pure IPv4 the other way around');
my $test = IP('18446462601965076481')->SIIT();
my $nf = $test->normal_form();
is("$test" , '192.168.0.1', "Pure IPv4 the other way around round-trip overloaded");
is($nf , '0000000000000000ffff0000c0a80001', "Pure IPv4 the other way around round-trip normal form");
}
{
# diag('IPv4-in-IPv6');
my $test = IP('::ffff:0:192.168.0.1')->SIIT();
my $nf = $test->normal_form();
is("$test" , '192.168.0.1', "IPv4-in-IPv6 round-trip");
is($nf , '0000000000000000ffff0000c0a80001', "IPv4-in-IPv6 round-trip normal form");
}
{
# diag('IPv4-as-IPv6');
my $test = IP('::ffff:0:c0a8:1')->SIIT();
my $nf = $test->normal_form();
is("$test" , '192.168.0.1', "IPv4-as-IPv6 round-trip");
is($nf , '0000000000000000ffff0000c0a80001', "IPv4-as-IPv6 round-trip normal form");
}
{
# diag('Pure IPv6');
my $test = IP('12::34')->SIIT();
my $nf = $test->normal_form();
is("$test" , '12::34', "Pure IPv6 round-trip");
is($nf , '00120000000000000000000000000034', "Pure IPv6 round-trip normal form");
}
{
( run in 1.631 second using v1.01-cache-2.11-cpan-364913b4093 )