File: test_deriving_create.ml

package info (click to toggle)
ppx-deriving 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 532 kB
  • sloc: ml: 3,983; makefile: 26; sh: 15
file content (58 lines) | stat: -rw-r--r-- 1,561 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
open OUnit2

module M : sig
  type a = {
    a1  : int option;
    a2  : int list;
    a3  : int [@default 42];
    a4s : (int * int list) [@split];
    a5  : int;
  } [@@deriving show, create]

  type b = {
    b1  : int option;
    b2  : int list;
    b3  : int [@default 42];
    b4s : (int * int list) [@split];
    b5  : int [@main];
  } [@@deriving show, create]
end = struct
  type a = {
    a1  : int option;
    a2  : int list;
    a3  : int [@default 42];
    a4s : (int * int list) [@split];
    a5  : int;
  } [@@deriving show, create]

  type b = {
    b1  : int option;
    b2  : int list;
    b3  : int [@default 42];
    b4s : (int * int list) [@split];
    b5  : int [@main];
  } [@@deriving show, create]
end

let test_no_main ctxt =
  assert_equal ~printer:M.show_a
               { M.a1 = None; a2 = []; a3 = 42; a4s = 2, []; a5 = 1 }
               (M.create_a ~a4:2 ~a5:1 ());
  assert_equal ~printer:M.show_a
               { M.a1 = Some 1; a2 = [2]; a3 = 3; a4s = 4, [5]; a5 = 6 }
               (M.create_a ~a1:1 ~a2:[2] ~a3:3 ~a4:4 ~a4s:[5] ~a5:6 ())

let test_main ctxt =
  assert_equal ~printer:M.show_b
               { M.b1 = None; b2 = []; b3 = 42; b4s = 2, []; b5 = 1 }
               (M.create_b ~b4:2 1);
  assert_equal ~printer:M.show_b
               { M.b1 = Some 1; b2 = [2]; b3 = 3; b4s = 4, [5]; b5 = 6 }
               (M.create_b ~b1:1 ~b2:[2] ~b3:3 ~b4:4 ~b4s:[5] 6)

let suite = "Test deriving(create)" >::: [
    "test_no_main" >:: test_no_main;
    "test_main"    >:: test_main;
  ]

let _ = run_test_tt_main suite