tiny_httpd/tests/unit/t_io.ml
Simon Cruanes b6cd59f084
add tests
2024-06-18 16:47:25 -04:00

24 lines
627 B
OCaml

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