Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppx: fix some tests #48

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ppx/test/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(cram
(deps
(package melange-json)
(package melange-json-native)
./example.ml
./example_json_string.ml
./run.sh
Expand Down
159 changes: 83 additions & 76 deletions ppx/test/ppx_deriving_json_js.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
61 changes: 33 additions & 28 deletions ppx/test/ppx_deriving_json_native.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
Loading