mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 05:24:40 +01:00
Fix IpAddress.setPort
This commit is contained in:
parent
251f54d1d7
commit
37109fa4ef
1 changed files with 8 additions and 2 deletions
|
|
@ -153,8 +153,9 @@ pub const IpAddress = union(enum) {
|
|||
|
||||
/// `port` is native-endian.
|
||||
pub fn setPort(a: *IpAddress, port: u16) void {
|
||||
switch (a) {
|
||||
inline .ip4, .ip6 => |*x| x.port = port,
|
||||
switch (a.*) {
|
||||
.ip4 => a.ip4.port = port,
|
||||
.ip6 => a.ip6.port = port,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1430,6 +1431,11 @@ test "parsing IPv6 addresses" {
|
|||
try testIp6Parse("ff02::");
|
||||
try testIp6Parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||
}
|
||||
test "IpAddress.setPort works" {
|
||||
var addr: IpAddress = .{ .ip4 = undefined };
|
||||
addr.setPort(0);
|
||||
try std.testing.expectEqual(0, addr.getPort());
|
||||
}
|
||||
|
||||
fn testIp6Parse(input: []const u8) !void {
|
||||
return testIp6ParseTransform(input, input);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue