mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
more tests
This commit is contained in:
parent
a5a06f0159
commit
66f87b7bda
7 changed files with 37 additions and 3 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
(tests
|
(tests
|
||||||
(names t1 t2)
|
(names t_chunk t_parse t_content_type)
|
||||||
(libraries tiny_httpd tiny_httpd.multipart-form-data))
|
(libraries tiny_httpd tiny_httpd.multipart-form-data))
|
||||||
|
|
|
||||||
3
tests/multipart_form/t_content_type.expected
Normal file
3
tests/multipart_form/t_content_type.expected
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
h: ["content-type": "yolo";"other": "whatev"], no content type
|
||||||
|
h ["content-type": "multipart/form-data; boundary=helloworld; junk";"other": "whatev"]: got "helloworld", expected "helloworld", same=true
|
||||||
|
h ["content-type": "multipart/form-data; lol=mdr; boundary=\"some quoted boundary\""]: got "some quoted boundary", expected "some quoted boundary", same=true
|
||||||
32
tests/multipart_form/t_content_type.ml
Normal file
32
tests/multipart_form/t_content_type.ml
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
module MFD = Tiny_httpd_multipart_form_data
|
||||||
|
|
||||||
|
let pf = Printf.printf
|
||||||
|
let spf = Printf.sprintf
|
||||||
|
|
||||||
|
let pp_headers hs =
|
||||||
|
spf "[%s]" (String.concat ";" @@ List.map (fun (k, v) -> spf "%S: %S" k v) hs)
|
||||||
|
|
||||||
|
let test_headers h (exp : string option) =
|
||||||
|
match MFD.parse_content_type h, exp with
|
||||||
|
| Some (`boundary c1), Some c2 ->
|
||||||
|
pf "h %s: got %S, expected %S, same=%b\n" (pp_headers h) c1 c2 (c1 = c2)
|
||||||
|
| Some (`boundary c1), None ->
|
||||||
|
pf "h: %s, unexpected content type %S\n" (pp_headers h) c1
|
||||||
|
| None, Some c2 -> pf "h: %s, expected content type %S\n" (pp_headers h) c2
|
||||||
|
| None, None -> pf "h: %s, no content type\n" (pp_headers h)
|
||||||
|
|
||||||
|
let () =
|
||||||
|
test_headers [ "content-type", "yolo"; "other", "whatev" ] None;
|
||||||
|
test_headers
|
||||||
|
[
|
||||||
|
"content-type", "multipart/form-data; boundary=helloworld; junk";
|
||||||
|
"other", "whatev";
|
||||||
|
]
|
||||||
|
(Some "helloworld");
|
||||||
|
test_headers
|
||||||
|
[
|
||||||
|
( "content-type",
|
||||||
|
"multipart/form-data; lol=mdr; boundary=\"some quoted boundary\"" );
|
||||||
|
]
|
||||||
|
(Some "some quoted boundary");
|
||||||
|
()
|
||||||
Loading…
Add table
Reference in a new issue