File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,25 @@ let test_variant_printer ctxt =
233
233
assert_equal ~printer
234
234
" fourth: 8 4" (show_variant_printer (Fourth (8 ,4 )))
235
235
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
+
236
255
type no_full = NoFull of int [@@ deriving show { with_path = false }]
237
256
type with_full = WithFull of int [@@ deriving show { with_path = true }]
238
257
module WithFull = struct
@@ -264,6 +283,7 @@ let suite = "Test deriving(show)" >::: [
264
283
" test_std_shadowing" > :: test_std_shadowing;
265
284
" test_poly_app" > :: test_poly_app;
266
285
" test_variant_printer" > :: test_variant_printer;
286
+ " test_poly_variant_printer" > :: test_poly_variant_printer;
267
287
" test_paths" > :: test_paths_printer;
268
288
" test_result" > :: test_result;
269
289
" test_result_result" > :: test_result_result;
You can’t perform that action at this time.
0 commit comments