@@ -15,9 +15,18 @@ Tests for deriving `jsProperties, getSet`
15
15
> let t = t ~action:(\` String "hello") () in
16
16
> (* Set action and expect the value to be unwrapped in the object too *)
17
17
> actionSet t (\` String "hello2");
18
- > Js.log2 "Action after setting: " t
18
+ > Js.log2 "Action after setting: " t;
19
+ > (* Expect the value to be what we declared in the type, but it isn't *)
20
+ > let action: [ \` String of string | \` Int of int ] option = actionGet t in
21
+ > (* This is, therefore, unsound *)
22
+ > match action with
23
+ > | None -> ()
24
+ > | Some (\` String s) ->
25
+ > Js.log2 "action in t is string:" s;
26
+ > | Some (\` Int i) ->
27
+ > Js.log2 "action in t is int:" i;
19
28
> EOF
20
- $ melc -ppx melppx -dsource x.ml
29
+ $ melc -ppx melppx -dsource x.ml | tee x.js
21
30
type t =
22
31
{
23
32
mutable action: [ `String of string | `Int of int ] option
@@ -54,7 +63,15 @@ Tests for deriving `jsProperties, getSet`
54
63
((actionSet t (`String "hello2"))
55
64
[@ocaml .warning "-ignored-extra-argument"]);
56
65
((Js.log2 "Action after setting: " t)
57
- [@ocaml .warning "-ignored-extra-argument"])
66
+ [@ocaml .warning "-ignored-extra-argument"]);
67
+ (let action : [ `String of string | `Int of int ] option = ((actionGet t)
68
+ [@ocaml .warning "-ignored-extra-argument"]) in
69
+ match action with
70
+ | None -> ()
71
+ | Some (`String s) -> ((Js.log2 "action in t is string:" s)
72
+ [@ocaml .warning "-ignored-extra-argument"])
73
+ | Some (`Int i) -> ((Js.log2 "action in t is int:" i)
74
+ [@ocaml .warning "-ignored-extra-argument"]))
58
75
// Generated by Melange
59
76
'use strict';
60
77
@@ -67,7 +84,18 @@ Tests for deriving `jsProperties, getSet`
67
84
68
85
console.log("Action after setting: ", t);
69
86
87
+ const action = t.action;
88
+
89
+ if (action !== undefined) {
90
+ if (action.NAME === "Int") {
91
+ console.log("action in t is int:", action.VAL);
92
+ } else {
93
+ console.log("action in t is string:", action.VAL);
94
+ }
95
+ }
96
+
70
97
/* Not a pure module */
71
98
72
-
73
-
99
+ $ node x.js
100
+ Action after setting: { action: 'hello2' }
101
+ action in t is string: undefined
0 commit comments