# HG changeset patch # User Kim Alvefur # Date 1468324742 -7200 # Node ID f67b7509ee2843fcf229300acd9e359eeb940044 # Parent 9a749cf8c1baa6535e1e3c3fd43e064c17593517 tests: Add basic test for net.http.parser diff -r 9a749cf8c1ba -r f67b7509ee28 tests/test.lua --- 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"); diff -r 9a749cf8c1ba -r f67b7509ee28 tests/test_net_http_parser.lua --- /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