mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
and tests
This commit is contained in:
parent
b966a9eccc
commit
ce6119d456
3 changed files with 43 additions and 1 deletions
|
|
@ -1,3 +1,3 @@
|
|||
(tests
|
||||
(names t_chunk t_parse t_content_type)
|
||||
(names t_chunk t_parse t_content_type t_content_disposition)
|
||||
(libraries tiny_httpd tiny_httpd.multipart-form-data))
|
||||
|
|
|
|||
3
tests/multipart_form/t_content_disposition.expected
Normal file
3
tests/multipart_form/t_content_disposition.expected
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
h: ["content-foobar": "yolo";"other": "whatev"], no content disp
|
||||
h ["content-disposition": "form-data; name=helloworld; junk";"other": "whatev"]: got {kind="form-data"; name="helloworld"; filename=None}, expected {kind="form-data"; name="helloworld"; filename=None}, same=true
|
||||
h ["content-disposition": "form-data; lol=mdr; filename=\"some quoted stuff\""]: got {kind="form-data"; name=None; filename="some quoted stuff"}, expected {kind="form-data"; name=None; filename="some quoted stuff"}, same=true
|
||||
39
tests/multipart_form/t_content_disposition.ml
Normal file
39
tests/multipart_form/t_content_disposition.ml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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 : _ option) =
|
||||
match MFD.Content_disposition.parse h, exp with
|
||||
| Some c1, Some c2 ->
|
||||
pf "h %s: got %s, expected %s, same=%b\n" (pp_headers h)
|
||||
(MFD.Content_disposition.to_string c1)
|
||||
(MFD.Content_disposition.to_string c2)
|
||||
(c1 = c2)
|
||||
| Some c1, None ->
|
||||
pf "h: %s, unexpected content disp %s\n" (pp_headers h)
|
||||
(MFD.Content_disposition.to_string c1)
|
||||
| None, Some c2 ->
|
||||
pf "h: %s, expected content disp %s\n" (pp_headers h)
|
||||
(MFD.Content_disposition.to_string c2)
|
||||
| None, None -> pf "h: %s, no content disp\n" (pp_headers h)
|
||||
|
||||
let () =
|
||||
test_headers [ "content-foobar", "yolo"; "other", "whatev" ] None;
|
||||
test_headers
|
||||
[
|
||||
"content-disposition", "form-data; name=helloworld; junk";
|
||||
"other", "whatev";
|
||||
]
|
||||
(Some { kind = "form-data"; name = Some "helloworld"; filename = None });
|
||||
test_headers
|
||||
[
|
||||
( "content-disposition",
|
||||
"form-data; lol=mdr; filename=\"some quoted stuff\"" );
|
||||
]
|
||||
(Some
|
||||
{ kind = "form-data"; name = None; filename = Some "some quoted stuff" });
|
||||
()
|
||||
Loading…
Add table
Reference in a new issue