From 1bd0efb067b7c1939f4d68c9014b7d67cb4e7020 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Thu, 15 Mar 2018 15:44:12 +0200 Subject: Fixed crash/interface. Added tests. --- tests/stdlib/tnet.nim | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests/stdlib/tnet.nim') diff --git a/tests/stdlib/tnet.nim b/tests/stdlib/tnet.nim index e8ada05e7..64d690fc9 100644 --- a/tests/stdlib/tnet.nim +++ b/tests/stdlib/tnet.nim @@ -1,4 +1,4 @@ -import net +import net, nativesockets import unittest suite "isIpAddress tests": @@ -45,3 +45,33 @@ suite "parseIpAddress tests": test "invalid ipv6": expect(ValueError): discard parseIpAddress("gggg:cdba:0000:0000:0000:0000:3257:9652") + +block: # "IpAddress/Sockaddr conversion" + proc test(ipaddrstr: string) = + var ipaddr_1 = parseIpAddress(ipaddrstr) + # echo ipaddrstr, " ", $ipaddr_1 + + doAssert($ipaddrstr == $ipaddr_1) + + var sockaddr: Sockaddr_storage + var socklen: Socklen + var ipaddr_2: IpAddress + var port_2: Port + + toSockAddr(ipaddr_1, Port(0), sockaddr, socklen) + fromSockAddr(sockaddr, socklen, ipaddr_2, port_2) + + doAssert(ipaddrstr == $ipaddr_1) + + doAssert(ipaddr_1 == ipaddr_2) + doAssert($ipaddr_1 == $ipaddr_2) + + + # ipv6 address of example.com + test("2606:2800:220:1:248:1893:25c8:1946") + # ipv6 address of localhost + test("::1") + # ipv4 address of example.com + test("93.184.216.34") + # ipv4 address of localhost + test("127.0.0.1") -- cgit 1.4.1-2-gfad0 ffbc3d318911da5c46582a70288dd16275f3'>commit diff stats
path: root/compiler.nimble
blob: 5929df3ec73f50ba5710546ee45d53eaeb5625f0 (plain) (tree)
1
2
3
4
5
6
7
8
9