diff options
author | Stephane Glondu <steph@glondu.net> | 2017-07-21 17:35:15 +0200 |
---|---|---|
committer | Stephane Glondu <steph@glondu.net> | 2017-07-21 17:35:15 +0200 |
commit | 730019fc84dc7a417f0c39796d0d68fb8ad8c560 (patch) | |
tree | b1642cd10ca8eb6fa5c265e246126386e34daced /src_test | |
parent | f61780054cc2f0620f6cb3d06474afabb90a152a (diff) |
New upstream version 4.1
Diffstat (limited to 'src_test')
-rw-r--r-- | src_test/test_deriving_map.cppo.ml | 24 | ||||
-rw-r--r-- | src_test/test_deriving_show.cppo.ml | 14 |
2 files changed, 31 insertions, 7 deletions
diff --git a/src_test/test_deriving_map.cppo.ml b/src_test/test_deriving_map.cppo.ml index d6f7e9f..6408d63 100644 --- a/src_test/test_deriving_map.cppo.ml +++ b/src_test/test_deriving_map.cppo.ml @@ -26,6 +26,11 @@ module T : sig type ('a,'b) record3 = { a3 : 'a; b3 : bool; c3 : 'b } [@@deriving map,show] + type ('a,'b) pvar0 = [ `A of 'a | `B of ('a,'b) pvar0 | `C of 'b ] [@@deriving map,show] + type ('a,'b,'c) pvar1 = [ ('a,'b) pvar0 | `D of 'c | `E of ('b,'c) pvar0 ] [@@deriving map,show] + type pvar2 = [ `F | `G ] [@@deriving map,show] + type ('a,'b,'c) pvar3 = [ pvar2 | ('a,'b,'c) pvar1 ] [@@deriving map,show] + end = struct type 'a btree = Node of 'a btree * 'a * 'a btree | Leaf @@ -57,6 +62,11 @@ end = struct type ('a,'b) record3 = { a3 : 'a; b3 : bool; c3 : 'b } [@@deriving map,show] + type ('a,'b) pvar0 = [ `A of 'a | `B of ('a,'b) pvar0 | `C of 'b ] [@@deriving map,show] + type ('a,'b,'c) pvar1 = [ ('a,'b) pvar0 | `D of 'c | `E of ('b,'c) pvar0 ] [@@deriving map,show] + type pvar2 = [ `F | `G ] [@@deriving map,show] + type ('a,'b,'c) pvar3 = [ pvar2 | ('a,'b,'c) pvar1 ] [@@deriving map,show] + end open T @@ -118,6 +128,19 @@ let test_record3 ctxt = assert_equal ~printer:(show_record3 fmt_int fmt_flt) {a3=97;b3=false;c3=4.} (map_record3 Char.code float_of_int {a3='a';b3=false;c3=4}) +let test_pvar3 ctxt = + let show,map = show_pvar3 fmt_str fmt_int fmt_int, + map_pvar3 string_of_int Char.code int_of_string + in + assert_equal ~printer:show (`A "1") (map (`A 1)); + assert_equal ~printer:show (`B (`A "1")) (map (`B (`A 1))); + assert_equal ~printer:show (`B (`C 97)) (map (`B (`C 'a'))); + assert_equal ~printer:show (`D 1) (map (`D "1")); + assert_equal ~printer:show (`E (`A 97)) (map (`E (`A 'a'))); + assert_equal ~printer:show (`E (`C 9)) (map (`E (`C "9"))); + assert_equal ~printer:show `F (map `F); + assert_equal ~printer:show `G (map `G) + type 'a result0 = ('a, bool) Result.result [@@deriving show, map] let test_map_result ctxt = @@ -136,6 +159,7 @@ let suite = "Test deriving(map)" >::: [ "test_record1" >:: test_record1; "test_record2" >:: test_record2; "test_record3" >:: test_record3; + "test_pvar3" >:: test_pvar3; "test_map_result" >:: test_map_result ] diff --git a/src_test/test_deriving_show.cppo.ml b/src_test/test_deriving_show.cppo.ml index da2fd10..c5c2873 100644 --- a/src_test/test_deriving_show.cppo.ml +++ b/src_test/test_deriving_show.cppo.ml @@ -43,9 +43,9 @@ let test_alias ctxt = type v = Foo | Bar of int * string | Baz of string [@@deriving show] let test_variant ctxt = - assert_equal ~printer "Test_deriving_show.Foo" (show_v Foo); - assert_equal ~printer "Test_deriving_show.Bar (1, \"foo\")" (show_v (Bar (1, "foo"))); - assert_equal ~printer "(Test_deriving_show.Baz \"foo\")" (show_v (Baz "foo")) + assert_equal ~printer "Test_deriving_show.Foo" (show_v Foo); + assert_equal ~printer "(Test_deriving_show.Bar (1, \"foo\"))" (show_v (Bar (1, "foo"))); + assert_equal ~printer "(Test_deriving_show.Baz \"foo\")" (show_v (Baz "foo")) #if OCAML_VERSION >= (4, 03, 0) type rv = RFoo | RBar of { x: int; y: string } | RBaz of { z: string } [@@deriving show] @@ -126,8 +126,8 @@ let print_hi = fun fmt _ -> Format.fprintf fmt "hi!" type polypr = (string [@printer print_hi]) btree [@polyprinter pp_btree] [@@deriving show] let test_polypr ctxt = - assert_equal ~printer "Test_deriving_show.Node (Test_deriving_show.Leaf, hi!,\n\ - \ Test_deriving_show.Leaf)" + assert_equal ~printer "(Test_deriving_show.Node (Test_deriving_show.Leaf, hi!,\n\ + \ Test_deriving_show.Leaf))" (show_polypr (Node (Leaf, "x", Leaf))) let test_placeholder ctxt = @@ -176,10 +176,10 @@ let test_std_shadowing ctxt = let e1 = ESBool (Bfoo (1, (+) 1)) in let e2 = ESString (Sfoo ("lalala", (+) 3)) in assert_equal ~printer - "(Test_deriving_show.ESBool Test_deriving_show.Bfoo (1, <fun>))" + "(Test_deriving_show.ESBool (Test_deriving_show.Bfoo (1, <fun>)))" (show_es e1); assert_equal ~printer - "(Test_deriving_show.ESString Test_deriving_show.Sfoo (\"lalala\", <fun>))" + "(Test_deriving_show.ESString (Test_deriving_show.Sfoo (\"lalala\", <fun>)))" (show_es e2) type poly_app = float poly_abs |