| ... | @@ -3,7 +3,7 @@ const net = std.net; | ... | @@ -3,7 +3,7 @@ const net = std.net; |
| 3 | const mem = std.mem; | 3 | const mem = std.mem; |
| 4 | const testing = std.testing; | 4 | const testing = std.testing; |
| 5 | | 5 | |
| 6 | test "std.net.parseIp4" { | 6 | test "parseIp4" { |
| 7 | testing.expect((try net.parseIp4("127.0.0.1")) == mem.bigToNative(u32, 0x7f000001)); | 7 | testing.expect((try net.parseIp4("127.0.0.1")) == mem.bigToNative(u32, 0x7f000001)); |
| 8 | | 8 | |
| 9 | testParseIp4Fail("256.0.0.1", error.Overflow); | 9 | testParseIp4Fail("256.0.0.1", error.Overflow); |
| ... | @@ -21,7 +21,7 @@ fn testParseIp4Fail(buf: []const u8, expected_err: anyerror) void { | ... | @@ -21,7 +21,7 @@ fn testParseIp4Fail(buf: []const u8, expected_err: anyerror) void { |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | | 23 | |
| 24 | test "std.net.parseIp6" { | 24 | test "parseIp6" { |
| 25 | const ip6 = try net.parseIp6("FF01:0:0:0:0:0:0:FB"); | 25 | const ip6 = try net.parseIp6("FF01:0:0:0:0:0:0:FB"); |
| 26 | const addr = net.Address.initIp6(ip6, 80); | 26 | const addr = net.Address.initIp6(ip6, 80); |
| 27 | var buf: [100]u8 = undefined; | 27 | var buf: [100]u8 = undefined; |
| ... | @@ -29,6 +29,20 @@ test "std.net.parseIp6" { | ... | @@ -29,6 +29,20 @@ test "std.net.parseIp6" { |
| 29 | std.testing.expect(mem.eql(u8, "[ff01::fb]:80", printed)); | 29 | std.testing.expect(mem.eql(u8, "[ff01::fb]:80", printed)); |
| 30 | } | 30 | } |
| 31 | | 31 | |
| | 32 | test "ip4s" { |
| | 33 | var buffer: [18]u8 = undefined; |
| | 34 | for ([_][]const u8{ |
| | 35 | "0.0.0.0", |
| | 36 | "255.255.255.255", |
| | 37 | "1.2.3.4", |
| | 38 | "123.255.0.91", |
| | 39 | }) |ip| { |
| | 40 | var addr = Address.initIp4(parseIp4(ip) catch unreachable, 0); |
| | 41 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable; |
| | 42 | std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); |
| | 43 | } |
| | 44 | } |
| | 45 | |
| 32 | test "resolve DNS" { | 46 | test "resolve DNS" { |
| 33 | if (std.builtin.os == .windows) { | 47 | if (std.builtin.os == .windows) { |
| 34 | // DNS resolution not implemented on Windows yet. | 48 | // DNS resolution not implemented on Windows yet. |