Added tests.
h3rald h3rald@h3rald.com
Sun, 19 Nov 2017 14:48:05 +0100
3 files changed,
58 insertions(+),
4 deletions(-)
M
lib/min_net.nim
→
lib/min_net.nim
@@ -1,4 +1,4 @@
-import net, nativesockets +import net, nativesockets, strutils import ../core/parser, ../core/value,@@ -17,7 +17,6 @@
def.symbol("socket") do (i: In): let vals = i.expect "dict" var q = vals[0] - # ((domain ipv4) (type stream) (protocol tcp)) var domain = AF_INET sockettype = SOCK_STREAM@@ -126,8 +125,7 @@
def.symbol("recv-line") do (i: In): let vals = i.expect("dict:socket") let skt = vals[0] - var s = "" - skt.toSocket.readLine(s) + var s = skt.toSocket.recvLine() i.push s.newVal def.finalize("net")
M
tests/all.min
→
tests/all.min
@@ -20,6 +20,7 @@ 'time load
'fs load 'crypto load 'math load +'net load "=" 70 repeat puts! "Total Failures: $1" (failures) => % puts! failures exit
A
tests/net.min
@@ -0,0 +1,55 @@
+'test load +'test import + +"net" describe + + () socket =srv1 + () socket =srv2 + () socket =cli1 + () socket =cli2 + + + () socket "httpbin.org" 80 connect #cli1 + "min v$1" (version) => % :user-agent + + "GET /user-agent HTTP/1.1\r\nHost: httpbin.org\r\nUser-Agent: $1\r\n\r\n" (user-agent) => % :request + + "" :response + cli1 request send + + cli1 recv-line :line + (response line) => "\n" join @response + (line "}" !=) + ( + cli1 recv-line @line + (response line) => "\n" join @response + ) while + + ;HTTP/1.1 200 OK + ;Connection: keep-alive + ;Server: meinheld/0.6.1 + ;Date: Sun, 19 Nov 2017 13:37:15 GMT + ;Content-Type: application/json + ;Access-Control-Allow-Origin: * + ;Access-Control-Allow-Credentials: true + ;X-Powered-By: Flask + ;X-Processed-Time: 0.00111794471741 + ;Content-Length: 34 + ;Via: 1.1 vegur + ; + ;{ + ; "user-agent": "min v0.12.0" + ;} + + (response "\n\n" split 1 get from-json "user-agent" dget user-agent ==) assert + + (srv1 srv2 ==) assert + (cli1 cli2 !=) assert + + report + clear-stack + srv1 close + srv2 close + cli1 close + cli2 close +