Annotate

tests/test_net_http_parser.lua @ 7611:0231b50ec959

configure: Remove unused 'find_helper' function
author Kim Alvefur <zash@zash.se>
date Fri, 19 Aug 2016 15:55:55 +0200
parent 7493:f67b7509ee28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7493
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local httpstreams = { [[
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 GET / HTTP/1.1
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 Host: example.com
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 ]], [[
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 HTTP/1.1 200 OK
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 Content-Length: 0
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 ]], [[
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 HTTP/1.1 200 OK
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 Content-Length: 7
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 Hello
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 HTTP/1.1 200 OK
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 Transfer-Encoding: chunked
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 1
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 H
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 1
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 e
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 2
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 ll
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 1
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 o
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 0
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 ]]
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 }
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 function new(new)
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 for _, stream in ipairs(httpstreams) do
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local success;
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 local function success_cb(packet)
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 success = true;
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 stream = stream:gsub("\n", "\r\n");
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local parser = new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server")
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 for chunk in stream:gmatch("..?.?") do
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 parser:feed(chunk);
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 assert_is(success);
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 end
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46
f67b7509ee28 tests: Add basic test for net.http.parser
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end