Skip to content

Commit

Permalink
update ocamlformat (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavarri authored Dec 4, 2024
1 parent 438f922 commit 500cb42
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 108 deletions.
5 changes: 4 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
ppxlib
(opam-check-npm-deps :with-test) ; todo: use with-dev-setup once opam 2.2 is out
(ocaml-lsp-server :with-test)
(ocamlformat :with-test)))
(ocamlformat
(and
(>= "0.27.0")
:with-test))))

(package
(name melange-json-native)
Expand Down
2 changes: 1 addition & 1 deletion melange-json.opam
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ depends: [
"ppxlib"
"opam-check-npm-deps" {with-test}
"ocaml-lsp-server" {with-test}
"ocamlformat" {with-test}
"ocamlformat" {>= "0.27.0" & with-test}
"odoc" {with-doc}
]
build: [
Expand Down
158 changes: 82 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 @@ -674,45 +674,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_error
"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
"expected a non empty JSON array with element being a string"
else
Ppx_deriving_json_runtime.of_json_error
"expected a non empty JSON array"
else
Ppx_deriving_json_runtime.of_json_error
"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_error
"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
"expected a non empty JSON array with element being a \
string"
else
Ppx_deriving_json_runtime.of_json_error
"expected a non empty JSON array"
else
Ppx_deriving_json_runtime.of_json_error
"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 @@ -969,49 +972,52 @@

[@@@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_error
"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_error
"expected a JSON array of length 2";
B (b_of_json (Js.Array.unsafe_get array 1)))
else Ppx_deriving_json_runtime.of_json_error "invalid JSON"
else
Ppx_deriving_json_runtime.of_json_error
"expected a non empty JSON array with element being a string"
else
Ppx_deriving_json_runtime.of_json_error
"expected a non empty JSON array"
else
Ppx_deriving_json_runtime.of_json_error
"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_error
"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_error
"expected a JSON array of length 2";
B (b_of_json (Js.Array.unsafe_get array 1)))
else Ppx_deriving_json_runtime.of_json_error "invalid JSON"
else
Ppx_deriving_json_runtime.of_json_error
"expected a non empty JSON array with element being a \
string"
else
Ppx_deriving_json_runtime.of_json_error
"expected a non empty JSON array"
else
Ppx_deriving_json_runtime.of_json_error
"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
65 changes: 35 additions & 30 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 @@ -740,26 +743,28 @@
[@@@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)
| _ ->
raise
(Ppx_deriving_json_runtime.Of_json_error
(Ppx_deriving_json_runtime.Unexpected_variant
"unexpected variant"))
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)
| _ ->
raise
(Ppx_deriving_json_runtime.Of_json_error
(Ppx_deriving_json_runtime.Unexpected_variant
"unexpected variant"))
: 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

0 comments on commit 500cb42

Please sign in to comment.