Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas-from-XIV committed Mar 2, 2022
1 parent 5e7f07e commit 6636035
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/test_write.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
let to_string () =
Alcotest.(check string) __LOC__ Fixtures.json_string (Yojson.Safe.to_string Fixtures.json_value)

let to_file () =
let to_file_tests =
let test ?newline () =
let output_file = Filename.temp_file "test_yojson_to_file" ".json" in
let correction = match newline with
| None ->
Yojson.Safe.to_file output_file Fixtures.json_value;
Fixtures.json_string_newline
| Some newline ->
Yojson.Safe.to_file ~newline output_file Fixtures.json_value;
let suf = match newline with true -> "\n" | false -> "" in
Yojson.Safe.to_file ~suf output_file Fixtures.json_value;
if newline then
Fixtures.json_string_newline
else
Expand All @@ -25,9 +26,11 @@ let to_file () =
Alcotest.(check string) __LOC__ correction file_content;
Sys.remove output_file
in
test ();
test ~newline:true ();
test ~newline:false ()
[
"to_file with default settings", `Quick, (fun () -> test ());
"to_file with newline", `Quick, (fun () -> test ~newline:true ());
"to_file without newline", `Quick, (fun () -> test ~newline:false ());
]

(* List.to_seq is not available on old OCaml versions. *)
let rec list_to_seq = function
Expand All @@ -50,8 +53,8 @@ let seq_to_file () =
but we don't have a 'testable' instance for JSON values. *)
Alcotest.fail "seq_{to,from}_file roundtrip failure"

let single_json = [
let single_json =
to_file_tests @ [
"to_string", `Quick, to_string;
"to_file", `Quick, to_file;
"seq_to_file", `Quick, seq_to_file;
]

0 comments on commit 6636035

Please sign in to comment.