Skip to content

Commit b6cd59f

Browse files
committed
add tests
1 parent 199bcff commit b6cd59f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tests/unit/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
(tests
3-
(names t_util t_buf t_server)
3+
(names t_util t_buf t_server t_io)
44
(package tiny_httpd)
55
(libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util))

tests/unit/t_io.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
open Test_util
2+
open Tiny_httpd_core.IO
3+
4+
let spf = Printf.sprintf
5+
6+
(* one chunk *)
7+
let () =
8+
let io = Input.of_string "5\r\nhello\r\n0\r\n\r\nARGH" in
9+
let str =
10+
io
11+
|> Input.read_chunked ~bytes:(Bytes.create 4) ~fail:failwith
12+
|> Input.read_all_using ~buf:(Buf.create ())
13+
in
14+
assert_eq ~to_string:(spf "%S") "hello" str
15+
16+
(* two chunks *)
17+
let () =
18+
let io = Input.of_string "5\r\nhello\r\n6\r\n world\r\n0\r\n\r\nARGH" in
19+
let str =
20+
io
21+
|> Input.read_chunked ~bytes:(Bytes.create 4) ~fail:failwith
22+
|> Input.read_all_using ~buf:(Buf.create ())
23+
in
24+
assert_eq ~to_string:(spf "%S") "hello world" str

0 commit comments

Comments
 (0)