···14let record fields = Record fields
15let enum x = Enum x
16let string s = String s
0000000000
···14let record fields = Record fields
15let enum x = Enum x
16let string s = String s
17+18+let result ok err = function
19+ | Ok s -> variant "Ok" [ ok s ]
20+ | Error e -> variant "Error" [ err e ]
21+;;
22+23+let option f = function
24+ | None -> enum "None"
25+ | Some s -> variant "Some" [ f s ]
26+;;
-10
lib/fmt.ml
···37 | Some i -> fprintf fmt "@ %d" i
38;;
3940-let quote fmt s = Format.fprintf fmt "\"%s\"" s
41-42-let pp_olist pp_elem fmt =
43- Format.fprintf
44- fmt
45- "@[<3>[@ %a@ ]@]"
46- (pp_print_list ~pp_sep:(fun fmt () -> fprintf fmt ";@ ") pp_elem)
47-;;
48-49let char fmt c = Format.fprintf fmt "%c" c
50let bool = Format.pp_print_bool
51-let pp_str_list = pp_olist quote
52let lit s fmt () = pp_print_string fmt s
5354let to_to_string pp x =
···37 | Some i -> fprintf fmt "@ %d" i
38;;
3900000000040let char fmt c = Format.fprintf fmt "%c" c
41let bool = Format.pp_print_bool
042let lit s fmt () = pp_print_string fmt s
4344let to_to_string pp x =
-1
lib/fmt.mli
···1type formatter := Format.formatter
2type 'a t = formatter -> 'a -> unit
34-val pp_str_list : string list t
5val sexp : formatter -> string -> 'a t -> 'a -> unit
6val str : string t
7val optint : int option t
···1type formatter := Format.formatter
2type 'a t = formatter -> 'a -> unit
304val sexp : formatter -> string -> 'a t -> 'a -> unit
5val str : string t
6val optint : int option t
···1-(* ounit compatibility layer for fort tests *)
2-open OUnit2
3-4-type ('a, 'b) either =
5- | Left of 'a
6- | Right of 'b
7-8-let str_of_either f g = function
9- | Left a -> f a
10- | Right b -> g b
11-;;
12-13-let try_with f =
14- try Right (f ()) with
15- | exn -> Left exn
16-;;
17-18-let expect_equal_app ?printer ?msg f x g y =
19- let fx = try_with (fun () -> f x) in
20- let gy = try_with (fun () -> g y) in
21- let printer =
22- let right x =
23- match printer with
24- | None -> "<no printer>"
25- | Some p -> p x
26- in
27- str_of_either Printexc.to_string right
28- in
29- assert_equal ~printer ?msg fx gy
30-;;
31-32-let collected_tests = ref []
33-let id x = x
34-let not_found () = raise Not_found
35-let bool_printer i = Printf.sprintf "%b" i
36-let int_printer i = Printf.sprintf "%d" i
37-let str_printer s = "\"" ^ String.escaped s ^ "\""
38-let ofs_printer (i0, i1) = Printf.sprintf "(%d,%d)" i0 i1
39-let list_printer f l = "[" ^ String.concat "; " (List.map f l) ^ "]"
40-let arr_printer f a = "[|" ^ String.concat "; " (List.map f (Array.to_list a)) ^ "|]"
41-42-let opt_printer f = function
43- | None -> "<None>"
44- | Some s -> "Some (" ^ f s ^ ")"
45-;;
46-47-let arr_str_printer = arr_printer str_printer
48-let arr_ofs_printer = arr_printer ofs_printer
49-let list_ofs_printer = list_printer ofs_printer
50-let fail = assert_failure
51-let expect_eq_bool ?msg f x g y = expect_equal_app ?msg ~printer:string_of_bool f x g y
52-let expect_eq_str ?msg f x g y = expect_equal_app ?msg ~printer:str_printer f x g y
53-54-let expect_eq_str_opt ?msg f x g y =
55- expect_equal_app ?msg ~printer:(opt_printer str_printer) f x g y
56-;;
57-58-let expect_eq_ofs ?msg f x g y = expect_equal_app ?msg ~printer:ofs_printer f x g y
59-60-let expect_eq_arr_str ?msg f x g y =
61- expect_equal_app ?msg ~printer:arr_str_printer f x g y
62-;;
63-64-let expect_eq_arr_ofs ?msg f x g y =
65- expect_equal_app ?msg ~printer:arr_ofs_printer f x g y
66-;;
67-68-let expect_eq_list_str ?msg f x g y =
69- expect_equal_app ?msg ~printer:(list_printer str_printer) f x g y
70-;;
71-72-let expect_pass name run =
73- collected_tests := (name >:: fun _ -> run ()) :: !collected_tests
74-;;
75-76-let run_test_suite suite_name = run_test_tt_main (suite_name >::: !collected_tests)