diff --git a/tests/unit/dune b/tests/unit/dune index 7be0c4d9..b4ceef08 100644 --- a/tests/unit/dune +++ b/tests/unit/dune @@ -1,5 +1,5 @@ (tests - (names t_util t_buf t_server) + (names t_util t_buf t_server t_io) (package tiny_httpd) (libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util)) diff --git a/tests/unit/t_io.ml b/tests/unit/t_io.ml new file mode 100644 index 00000000..61400b4d --- /dev/null +++ b/tests/unit/t_io.ml @@ -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