diff --git a/tests/core/dune b/tests/core/dune index e17dd3a6..89c12c06 100644 --- a/tests/core/dune +++ b/tests/core/dune @@ -6,5 +6,6 @@ (preprocess (action (run %{project_root}/src/core/cpp/cpp.exe %{input-file}))) - (libraries containers containers.bencode containers.cbor containers.unix + (libraries containers containers.bencode containers.cbor + containers.unix containers.pp threads containers_testlib iter gen uutf csexp)) diff --git a/tests/core/t.ml b/tests/core/t.ml index e5d27999..8508555a 100644 --- a/tests/core/t.ml +++ b/tests/core/t.ml @@ -1,5 +1,6 @@ Containers_testlib.run_all ~descr:"containers" [ + T_pp.get (); T_list.get (); T_array.get (); T_bool.get (); diff --git a/tests/core/t_pp.ml b/tests/core/t_pp.ml new file mode 100644 index 00000000..b782a942 --- /dev/null +++ b/tests/core/t_pp.ml @@ -0,0 +1,41 @@ +include (val Containers_testlib.make ~__FILE__ ()) +open Containers_pp + +let spf = Printf.sprintf + +let () = + eq "hello world" (Flatten.to_string @@ text "hello" ^ newline ^ text "world") + +let () = + eq ~name:"l1" ~printer:(spf "%S") "[0; 1; 2; 3;\n 4; 5; 6; 7;\n 8; 9]" + (let d = Dump.list (List.init 10 int) in + Pretty.to_string ~width:10 d) + +let () = + eq ~name:"l2" ~printer:(spf "%S") + "[[0; 1; 2; 3;\n\ + \ 4; 5];\n\ + \ [1; 2; 3; 4;\n\ + \ 5; 6];\n\ + \ [2; 3; 4; 5;\n\ + \ 6; 7];\n\ + \ [3; 4; 5; 6;\n\ + \ 7; 8];\n\ + \ [4; 5; 6; 7;\n\ + \ 8; 9];\n\ + \ [5; 6; 7; 8;\n\ + \ 9; 10]]" + (let d = + Dump.list + (List.init 6 (fun i -> + Dump.list (List.init 6 (fun j -> int @@ (i + j))))) + in + Pretty.to_string ~width:10 d) + +let () = + eq ~name:"s1" ~printer:(spf "%S") "(foo\n bar\n baaz\n (g 42 10))" + (let d = + sexp_apply "foo" + [ text "bar"; text "baaz"; sexp_apply "g" [ int 42; int 10 ] ] + in + Pretty.to_string ~width:10 d)