ipv4/ipv6 parsing and back to string.

This commit is contained in:
Christoffer Lerno
2023-02-20 09:31:11 +01:00
parent 34eac23e23
commit d35d50555e
2 changed files with 108 additions and 2 deletions

View File

@@ -9,6 +9,25 @@ fn void test_ipv4() @test
}
fn void! test_ipv4_to_string() @test
{
InetAddress a = net::ipv4_from_str("127.0.0.1")?;
assert(a.to_string()? == "127.0.0.1");
}
fn void! test_ipv6_to_string() @test
{
InetAddress a = net::ipv6_from_str("2001:db8::2:1")?;
a.to_string()?;
assert(a.to_string()? == "2001:0db8:0000:0000:0000:0000:0002:0001");
assert(net::ipv6_from_str("2001:db8::1").to_string()? == "2001:0db8:0000:0000:0000:0000:0000:0001");
assert(net::ipv6_from_str("::1").to_string()? == "0000:0000:0000:0000:0000:0000:0000:0001");
assert(net::ipv6_from_str("2001::1").to_string()? == "2001:0000:0000:0000:0000:0000:0000:0001");
assert(net::ipv6_from_str("2001:db8:1234::").to_string()? == "2001:0db8:1234:0000:0000:0000:0000:0000");
assert(net::ipv6_from_str("2001::").to_string()? == "2001:0000:0000:0000:0000:0000:0000:0000");
assert(net::ipv6_from_str("::").to_string()? == "0000:0000:0000:0000:0000:0000:0000:0000");
}
fn void! test_ipv4_parse() @test
{
InetAddress a = net::ipv4_from_str("127.0.0.1")?;