Skip to content

Commit 4da03cd

Browse files
committed
Add test for show polymorphic variant @printer
1 parent 32f7c31 commit 4da03cd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src_test/show/test_deriving_show.cppo.ml

+20
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,25 @@ let test_variant_printer ctxt =
233233
assert_equal ~printer
234234
"fourth: 8 4" (show_variant_printer (Fourth(8,4)))
235235

236+
type poly_variant_printer = [
237+
| `First [@printer fun fmt _ -> Format.pp_print_string fmt "first"]
238+
| `Second of int [@printer fun fmt i -> fprintf fmt "second: %d" i]
239+
| `Third
240+
| `Fourth of int * int
241+
[@printer fun fmt (a,b) -> fprintf fmt "fourth: %d %d" a b]
242+
]
243+
[@@deriving show]
244+
245+
let test_poly_variant_printer ctxt =
246+
assert_equal ~printer
247+
"first" (show_poly_variant_printer `First);
248+
assert_equal ~printer
249+
"second: 42" (show_poly_variant_printer (`Second 42));
250+
assert_equal ~printer
251+
"`Third" (show_poly_variant_printer `Third);
252+
assert_equal ~printer
253+
"fourth: 8 4" (show_poly_variant_printer (`Fourth(8,4)))
254+
236255
type no_full = NoFull of int [@@deriving show { with_path = false }]
237256
type with_full = WithFull of int [@@deriving show { with_path = true }]
238257
module WithFull = struct
@@ -264,6 +283,7 @@ let suite = "Test deriving(show)" >::: [
264283
"test_std_shadowing" >:: test_std_shadowing;
265284
"test_poly_app" >:: test_poly_app;
266285
"test_variant_printer" >:: test_variant_printer;
286+
"test_poly_variant_printer" >:: test_poly_variant_printer;
267287
"test_paths" >:: test_paths_printer;
268288
"test_result" >:: test_result;
269289
"test_result_result" >:: test_result_result;

0 commit comments

Comments
 (0)