diff --git a/ppx/test/dune b/ppx/test/dune index 1e8909e..9cce5fb 100644 --- a/ppx/test/dune +++ b/ppx/test/dune @@ -1,6 +1,7 @@ (cram (deps (package melange-json) + (package melange-json-native) ./example.ml ./example_json_string.ml ./run.sh diff --git a/ppx/test/ppx_deriving_json_js.t b/ppx/test/ppx_deriving_json_js.t index 299e601..76a0873 100644 --- a/ppx/test/ppx_deriving_json_js.t +++ b/ppx/test/ppx_deriving_json_js.t @@ -52,15 +52,15 @@ [@@@ocaml.warning "-39-11-27"] - let rec param_of_json a_of_json : Js.Json.t -> 'a param = - fun x -> a_of_json x + let rec param_of_json a_of_json = + (fun x -> a_of_json x : Js.Json.t -> 'a param) let _ = param_of_json [@@@ocaml.warning "-39-11-27"] - let rec param_to_json a_to_json : 'a param -> Js.Json.t = - fun x -> a_to_json x + let rec param_to_json a_to_json = + (fun x -> a_to_json x : 'a param -> Js.Json.t) let _ = param_to_json end [@@ocaml.doc "@inline"] [@@merlin.hide] @@ -679,45 +679,48 @@ [@@@ocaml.warning "-39-11-27"] - let rec c_of_json a_of_json : Js.Json.t -> 'a c = - fun x -> - if Js.Array.isArray x then - let array = (Obj.magic x : Js.Json.t array) in - let len = Js.Array.length array in - if Stdlib.( > ) len 0 then - let tag = Js.Array.unsafe_get array 0 in - if Stdlib.( = ) (Js.typeof tag) "string" then - let tag = (Obj.magic tag : string) in - if Stdlib.( = ) tag "C" then ( - if Stdlib.( <> ) len 2 then - Ppx_deriving_json_runtime.of_json_msg_error ~json:x - "expected a JSON array of length 2"; - `C (a_of_json (Js.Array.unsafe_get array 1))) - else - raise - (Ppx_deriving_json_runtime.Of_json_error - (Ppx_deriving_json_runtime.Unexpected_variant - "unexpected variant")) - else - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected a non empty JSON array with element being a string" - else - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected a non empty JSON array" - else - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected a non empty JSON array" + let rec c_of_json a_of_json = + (fun x -> + if Js.Array.isArray x then + let array = (Obj.magic x : Js.Json.t array) in + let len = Js.Array.length array in + if Stdlib.( > ) len 0 then + let tag = Js.Array.unsafe_get array 0 in + if Stdlib.( = ) (Js.typeof tag) "string" then + let tag = (Obj.magic tag : string) in + if Stdlib.( = ) tag "C" then ( + if Stdlib.( <> ) len 2 then + Ppx_deriving_json_runtime.of_json_msg_error ~json:x + "expected a JSON array of length 2"; + `C (a_of_json (Js.Array.unsafe_get array 1))) + else + raise + (Ppx_deriving_json_runtime.Of_json_error + (Ppx_deriving_json_runtime.Unexpected_variant + "unexpected variant")) + else + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected a non empty JSON array with element being a \ + string" + else + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected a non empty JSON array" + else + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected a non empty JSON array" + : Js.Json.t -> 'a c) let _ = c_of_json [@@@ocaml.warning "-39-11-27"] - let rec c_to_json a_to_json : 'a c -> Js.Json.t = - fun x -> - match x with - | `C x_0 -> - (Obj.magic [| (Obj.magic "C" : Js.Json.t); a_to_json x_0 |] - : Js.Json.t) + let rec c_to_json a_to_json = + (fun x -> + match x with + | `C x_0 -> + (Obj.magic [| (Obj.magic "C" : Js.Json.t); a_to_json x_0 |] + : Js.Json.t) + : 'a c -> Js.Json.t) let _ = c_to_json end [@@ocaml.doc "@inline"] [@@merlin.hide] @@ -976,49 +979,53 @@ [@@@ocaml.warning "-39-11-27"] - let rec p2_of_json a_of_json b_of_json : Js.Json.t -> ('a, 'b) p2 = - fun x -> - if Js.Array.isArray x then - let array = (Obj.magic x : Js.Json.t array) in - let len = Js.Array.length array in - if Stdlib.( > ) len 0 then - let tag = Js.Array.unsafe_get array 0 in - if Stdlib.( = ) (Js.typeof tag) "string" then - let tag = (Obj.magic tag : string) in - if Stdlib.( = ) tag "A" then ( - if Stdlib.( <> ) len 2 then - Ppx_deriving_json_runtime.of_json_msg_error ~json:x - "expected a JSON array of length 2"; - A (a_of_json (Js.Array.unsafe_get array 1))) - else if Stdlib.( = ) tag "B" then ( - if Stdlib.( <> ) len 2 then - Ppx_deriving_json_runtime.of_json_msg_error ~json:x - "expected a JSON array of length 2"; - B (b_of_json (Js.Array.unsafe_get array 1))) - else Ppx_deriving_json_runtime.of_json_msg_error "invalid JSON" - else - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected a non empty JSON array with element being a string" - else - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected a non empty JSON array" - else - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected a non empty JSON array" + let rec p2_of_json a_of_json b_of_json = + (fun x -> + if Js.Array.isArray x then + let array = (Obj.magic x : Js.Json.t array) in + let len = Js.Array.length array in + if Stdlib.( > ) len 0 then + let tag = Js.Array.unsafe_get array 0 in + if Stdlib.( = ) (Js.typeof tag) "string" then + let tag = (Obj.magic tag : string) in + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 2 then + Ppx_deriving_json_runtime.of_json_msg_error ~json:x + "expected a JSON array of length 2"; + A (a_of_json (Js.Array.unsafe_get array 1))) + else if Stdlib.( = ) tag "B" then ( + if Stdlib.( <> ) len 2 then + Ppx_deriving_json_runtime.of_json_msg_error ~json:x + "expected a JSON array of length 2"; + B (b_of_json (Js.Array.unsafe_get array 1))) + else + Ppx_deriving_json_runtime.of_json_msg_error "invalid JSON" + else + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected a non empty JSON array with element being a \ + string" + else + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected a non empty JSON array" + else + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected a non empty JSON array" + : Js.Json.t -> ('a, 'b) p2) let _ = p2_of_json [@@@ocaml.warning "-39-11-27"] - let rec p2_to_json a_to_json b_to_json : ('a, 'b) p2 -> Js.Json.t = - fun x -> - match x with - | A x_0 -> - (Obj.magic [| (Obj.magic "A" : Js.Json.t); a_to_json x_0 |] - : Js.Json.t) - | B x_0 -> - (Obj.magic [| (Obj.magic "B" : Js.Json.t); b_to_json x_0 |] - : Js.Json.t) + let rec p2_to_json a_to_json b_to_json = + (fun x -> + match x with + | A x_0 -> + (Obj.magic [| (Obj.magic "A" : Js.Json.t); a_to_json x_0 |] + : Js.Json.t) + | B x_0 -> + (Obj.magic [| (Obj.magic "B" : Js.Json.t); b_to_json x_0 |] + : Js.Json.t) + : ('a, 'b) p2 -> Js.Json.t) let _ = p2_to_json end [@@ocaml.doc "@inline"] [@@merlin.hide] diff --git a/ppx/test/ppx_deriving_json_native.t b/ppx/test/ppx_deriving_json_native.t index cdabb25..baf312e 100644 --- a/ppx/test/ppx_deriving_json_native.t +++ b/ppx/test/ppx_deriving_json_native.t @@ -52,15 +52,15 @@ [@@@ocaml.warning "-39-11-27"] - let rec param_of_json a_of_json : Yojson.Basic.t -> 'a param = - fun x -> a_of_json x + let rec param_of_json a_of_json = + (fun x -> a_of_json x : Yojson.Basic.t -> 'a param) let _ = param_of_json [@@@ocaml.warning "-39-11-27"] - let rec param_to_json a_to_json : 'a param -> Yojson.Basic.t = - fun x -> a_to_json x + let rec param_to_json a_to_json = + (fun x -> a_to_json x : 'a param -> Yojson.Basic.t) let _ = param_to_json end [@@ocaml.doc "@inline"] [@@merlin.hide] @@ -566,22 +566,25 @@ [@@@ocaml.warning "-39-11-27"] - let rec c_of_json a_of_json : Yojson.Basic.t -> 'a c = - fun x -> - match x with - | `List [ `String "C"; x_0 ] -> `C (a_of_json x_0) - | x -> - raise - (Ppx_deriving_json_runtime.Of_json_error - (Ppx_deriving_json_runtime.Unexpected_variant - "unexpected variant")) + let rec c_of_json a_of_json = + (fun x -> + match x with + | `List [ `String "C"; x_0 ] -> `C (a_of_json x_0) + | x -> + raise + (Ppx_deriving_json_runtime.Of_json_error + (Ppx_deriving_json_runtime.Unexpected_variant + "unexpected variant")) + : Yojson.Basic.t -> 'a c) let _ = c_of_json [@@@ocaml.warning "-39-11-27"] - let rec c_to_json a_to_json : 'a c -> Yojson.Basic.t = - fun x -> match x with `C x_0 -> `List [ `String "C"; a_to_json x_0 ] + let rec c_to_json a_to_json = + (fun x -> + match x with `C x_0 -> `List [ `String "C"; a_to_json x_0 ] + : 'a c -> Yojson.Basic.t) let _ = c_to_json end [@@ocaml.doc "@inline"] [@@merlin.hide] @@ -736,24 +739,26 @@ [@@@ocaml.warning "-39-11-27"] - let rec p2_of_json a_of_json b_of_json : Yojson.Basic.t -> ('a, 'b) p2 = - fun x -> - match x with - | `List [ `String "A"; x_0 ] -> A (a_of_json x_0) - | `List [ `String "B"; x_0 ] -> B (b_of_json x_0) - | _ -> - Ppx_deriving_json_runtime.of_json_error ~json:x - "expected [\"A\", _] or [\"B\", _]" + let rec p2_of_json a_of_json b_of_json = + (fun x -> + match x with + | `List [ `String "A"; x_0 ] -> A (a_of_json x_0) + | `List [ `String "B"; x_0 ] -> B (b_of_json x_0) + | _ -> + Ppx_deriving_json_runtime.of_json_error ~json:x + "expected [\"A\", _] or [\"B\", _]" + : Yojson.Basic.t -> ('a, 'b) p2) let _ = p2_of_json [@@@ocaml.warning "-39-11-27"] - let rec p2_to_json a_to_json b_to_json : ('a, 'b) p2 -> Yojson.Basic.t = - fun x -> - match x with - | A x_0 -> `List [ `String "A"; a_to_json x_0 ] - | B x_0 -> `List [ `String "B"; b_to_json x_0 ] + let rec p2_to_json a_to_json b_to_json = + (fun x -> + match x with + | A x_0 -> `List [ `String "A"; a_to_json x_0 ] + | B x_0 -> `List [ `String "B"; b_to_json x_0 ] + : ('a, 'b) p2 -> Yojson.Basic.t) let _ = p2_to_json end [@@ocaml.doc "@inline"] [@@merlin.hide]