aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-10-30 12:33:47 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-10-30 12:33:47 -0400
commitf5ff36271bce54eaec6f20cdff4fa4efb833c0d4 (patch)
tree8773174d52c67f23b723a1f59a437fc6c6d52b58 /lib/std/net
parent0fb1388031ec98af77fe5e0ae8459c983010d1a8 (diff)
parent4e0c2ed443a0c13030decf8a9d53aff28f415005 (diff)
downloadzig-f5ff36271bce54eaec6f20cdff4fa4efb833c0d4.tar.gz
zig-f5ff36271bce54eaec6f20cdff4fa4efb833c0d4.zip
Merge branch 'testAddresses' of https://github.com/marler8997/zig into std.net
Diffstat (limited to 'lib/std/net')
-rw-r--r--lib/std/net/test.zig18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig
index aced17f1b5..6322401577 100644
--- a/lib/std/net/test.zig
+++ b/lib/std/net/test.zig
@@ -3,7 +3,7 @@ const net = std.net;
const mem = std.mem;
const testing = std.testing;
-test "std.net.parseIp4" {
+test "parseIp4" {
testing.expect((try net.parseIp4("127.0.0.1")) == mem.bigToNative(u32, 0x7f000001));
testParseIp4Fail("256.0.0.1", error.Overflow);
@@ -21,7 +21,7 @@ fn testParseIp4Fail(buf: []const u8, expected_err: anyerror) void {
}
}
-test "std.net.parseIp6" {
+test "parseIp6" {
const ip6 = try net.parseIp6("FF01:0:0:0:0:0:0:FB");
const addr = net.Address.initIp6(ip6, 80);
var buf: [100]u8 = undefined;
@@ -29,6 +29,20 @@ test "std.net.parseIp6" {
std.testing.expect(mem.eql(u8, "[ff01::fb]:80", printed));
}
+test "ip4s" {
+ var buffer: [18]u8 = undefined;
+ for ([_][]const u8{
+ "0.0.0.0",
+ "255.255.255.255",
+ "1.2.3.4",
+ "123.255.0.91",
+ }) |ip| {
+ var addr = Address.initIp4(parseIp4(ip) catch unreachable, 0);
+ var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
+ std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
+ }
+}
+
test "resolve DNS" {
if (std.builtin.os == .windows) {
// DNS resolution not implemented on Windows yet.