| ... | @@ -123,6 +123,22 @@ fn testIp4ParseAndRender(text: []const u8) !void { | ... | @@ -123,6 +123,22 @@ fn testIp4ParseAndRender(text: []const u8) !void { |
| 123 | try testing.expectEqualStrings(text, without_port); | 123 | try testing.expectEqualStrings(text, without_port); |
| 124 | } | 124 | } |
| 125 | | 125 | |
| | 126 | test "parse Ip4Address from IpAddress" { |
| | 127 | try testIp4FromIpAddress("0.0.0.0:80", "0.0.0.0:80"); |
| | 128 | try testIp4FromIpAddress("255.255.255.255:0", "255.255.255.255:0"); |
| | 129 | try testIp4FromIpAddress("[::ffff:127.0.0.1]:80", "127.0.0.1:80"); |
| | 130 | try testIp4FromIpAddress("[::ffff:192.168.1.1]:443", "192.168.1.1:443"); |
| | 131 | |
| | 132 | try testing.expectEqual(null, net.Ip4Address.fromAny(try net.IpAddress.parseIp6("2001:db8::1", 443))); |
| | 133 | try testing.expectEqual(null, net.Ip4Address.fromAny(try net.IpAddress.parseIp6("::c000:201", 80))); |
| | 134 | } |
| | 135 | |
| | 136 | fn testIp4FromIpAddress(any_address: []const u8, ip4_address: []const u8) !void { |
| | 137 | const expected = try net.IpAddress.parseLiteral(ip4_address); |
| | 138 | const actual = net.Ip4Address.fromAny(try net.IpAddress.parseLiteral(any_address)).?; |
| | 139 | try testing.expectEqual(expected.ip4, actual); |
| | 140 | } |
| | 141 | |
| 126 | test "resolve DNS" { | 142 | test "resolve DNS" { |
| 127 | const io = testing.io; | 143 | const io = testing.io; |
| 128 | | 144 | |