From 7df124f94c71324a7002d4ad650328ae7bc89808 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 14 Oct 2021 23:40:51 -0400 Subject: [PATCH] test: add a test using a file backend --- src/util/tests/test_chunk_stack.ml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/util/tests/test_chunk_stack.ml b/src/util/tests/test_chunk_stack.ml index 391e7a4b..4ad6f7da 100644 --- a/src/util/tests/test_chunk_stack.ml +++ b/src/util/tests/test_chunk_stack.ml @@ -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