Changeset

7493:f67b7509ee28

tests: Add basic test for net.http.parser
author Kim Alvefur <zash@zash.se>
date Tue, 12 Jul 2016 13:59:02 +0200
parents 7492:9a749cf8c1ba
children 7494:f82356adcd71 7496:98c8d14be4ef
files tests/test.lua tests/test_net_http_parser.lua
diffstat 2 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test.lua	Tue Jul 12 10:39:04 2016 +0200
+++ b/tests/test.lua	Tue Jul 12 13:59:02 2016 +0200
@@ -27,6 +27,7 @@
 	dotest "util.random"
 	dotest "util.xml"
 	dotest "util.xmppstream"
+	dotest "net.http.parser"
 
 	dosingletest("test_sasl.lua", "latin1toutf8");
 	dosingletest("test_utf8.lua", "valid");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_net_http_parser.lua	Tue Jul 12 13:59:02 2016 +0200
@@ -0,0 +1,47 @@
+local httpstreams = { [[
+GET / HTTP/1.1
+Host: example.com
+
+]], [[
+HTTP/1.1 200 OK
+Content-Length: 0
+
+]], [[
+HTTP/1.1 200 OK
+Content-Length: 7
+
+Hello
+HTTP/1.1 200 OK
+Transfer-Encoding: chunked
+
+1
+H
+1
+e
+2
+ll
+1
+o
+0
+
+
+]]
+}
+
+function new(new)
+
+	for _, stream in ipairs(httpstreams) do
+		local success;
+		local function success_cb(packet)
+			success = true;
+		end
+		stream = stream:gsub("\n", "\r\n");
+		local parser = new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server")
+		for chunk in stream:gmatch("..?.?") do
+			parser:feed(chunk);
+		end
+
+		assert_is(success);
+	end
+
+end