more tests

This commit is contained in:
Simon Cruanes 2024-12-02 14:45:41 -05:00
parent a5a06f0159
commit 66f87b7bda
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
7 changed files with 37 additions and 3 deletions

View file

@ -1,4 +1,3 @@
(tests
(names t1 t2)
(libraries tiny_httpd tiny_httpd.multipart-form-data))
(names t_chunk t_parse t_content_type)
(libraries tiny_httpd tiny_httpd.multipart-form-data))

View 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

View 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");
()