mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
Fixed crash/interface. Added tests.
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user