test: add a test using a file backend

This commit is contained in:
Simon Cruanes 2021-10-14 23:40:51 -04:00
parent 73cca4ca18
commit 7df124f94c
No known key found for this signature in database
GPG key ID: 4AC01D0849AA62B6

View file

@ -5,8 +5,8 @@ module C = Chunk_stack
let l : unit Alcotest.test_case list ref = ref []
let (~!) = Printf.sprintf "at line %d"
let mk_test name f =
l := (name, `Quick, f) :: !l
let mk_test ?(speed=`Quick) name f =
l := (name, speed, f) :: !l
let () = mk_test "inbuf" @@ fun () ->
let buf = C.Buf.create() in
@ -23,4 +23,21 @@ let () = mk_test "inbuf" @@ fun () ->
A.check A.(option string) ~!__LINE__ None (C.Reader.next_string reader);
()
let () = mk_test ~speed:`Slow "infile" @@ fun () ->
CCIO.File.with_temp ~prefix:"sidekick-test" ~suffix:"dat"
(fun file ->
CCIO.with_out file (fun oc ->
let writer = C.Writer.into_channel oc in
C.Writer.add_string writer "hello";
C.Writer.add_string writer "world";
C.Writer.add_string writer "!!\x00!");
C.Reader.with_file_backward file (fun reader ->
A.check A.(option string) ~!__LINE__ (Some "!!\x00!") (C.Reader.next_string reader);
A.check A.(option string) ~!__LINE__ (Some "world") (C.Reader.next_string reader);
A.check A.(option string) ~!__LINE__ (Some "hello") (C.Reader.next_string reader);
A.check A.(option string) ~!__LINE__ None (C.Reader.next_string reader));
()
)
let tests = "chunk_stack", !l