add tests

This commit is contained in:
Simon Cruanes 2024-06-18 16:47:25 -04:00
parent 199bcff68d
commit b6cd59f084
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 25 additions and 1 deletions

View file

@ -1,5 +1,5 @@
(tests (tests
(names t_util t_buf t_server) (names t_util t_buf t_server t_io)
(package tiny_httpd) (package tiny_httpd)
(libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util)) (libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util))

24
tests/unit/t_io.ml Normal file
View file

@ -0,0 +1,24 @@
open Test_util
open Tiny_httpd_core.IO
let spf = Printf.sprintf
(* one chunk *)
let () =
let io = Input.of_string "5\r\nhello\r\n0\r\n\r\nARGH" in
let str =
io
|> Input.read_chunked ~bytes:(Bytes.create 4) ~fail:failwith
|> Input.read_all_using ~buf:(Buf.create ())
in
assert_eq ~to_string:(spf "%S") "hello" str
(* two chunks *)
let () =
let io = Input.of_string "5\r\nhello\r\n6\r\n world\r\n0\r\n\r\nARGH" in
let str =
io
|> Input.read_chunked ~bytes:(Bytes.create 4) ~fail:failwith
|> Input.read_all_using ~buf:(Buf.create ())
in
assert_eq ~to_string:(spf "%S") "hello world" str