Skip to content

Commit

Permalink
Merge pull request #2 from melange-community/melange-v2
Browse files Browse the repository at this point in the history
upgrade to melange v2
  • Loading branch information
jchavarri authored Jun 23, 2023
2 parents fc261a7 + b2bee95 commit bfeb902
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion examples/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(melange.emit
(target examples)
(alias examples)
(libraries melange-json))
(libraries melange-json)
(preprocess (pps melange.ppx)))
2 changes: 1 addition & 1 deletion src/Json_encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let withDefault d encode = function
| None -> d
| Some v -> encode v

external jsonDict : Js.Json.t Js_dict.t -> Js.Json.t = "%identity"
external jsonDict : Js.Json.t Js.Dict.t -> Js.Json.t = "%identity"
let dict encode d =
let pairs = Js.Dict.entries d in
let encodedPairs = Array.map (fun (k, v) -> (k, encode(v))) pairs in
Expand Down
4 changes: 2 additions & 2 deletions src/Json_encode.mli
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ val tuple3 : 'a encoder -> 'b encoder -> 'c encoder -> ('a * 'b * 'c) -> Js.Json
val tuple4 : 'a encoder -> 'b encoder -> 'c encoder -> 'd encoder -> ('a * 'b * 'c * 'd) -> Js.Json.t
(** [tuple4 enc enc enc enc tuple] creates a JSON array from a tuple of size 4 *)

external jsonDict : Js.Json.t Js_dict.t -> Js.Json.t = "%identity"
external jsonDict : Js.Json.t Js.Dict.t -> Js.Json.t = "%identity"
(** [jsonDict d] makes a JSON object of the [Js.Dict.t] [d] *)

val dict : 'a encoder -> 'a Js_dict.t encoder
val dict : 'a encoder -> 'a Js.Dict.t encoder
(** [dict encoder d] makes a JSON object of the [Js.Dict.t] [d] with the given [encoder] *)

val object_ : (string * Js.Json.t) list -> Js.Json.t
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/Json_decode_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,15 @@ let () =
|> toEqual (Obj.magic [%obj { a = Js.null; b = Js.null }]));
test "null -> dict string" (fun () ->
try
let (_ : string Js_dict.t) =
let (_ : string Js.Dict.t) =
(dict string) (parseOrRaise {| { "a": null, "b": null } |})
in
fail "should throw"
with DecodeError "Expected string, got null\n\tin dict" -> pass);
test "non-DecodeError exceptions in decoder should pass through"
(fun () ->
try
let (_ : _ Js_dict.t) =
let (_ : _ Js.Dict.t) =
(dict (fun _ -> raise Foo)) (parseOrRaise {| { "a": 0 } |})
in
fail "should throw"
Expand Down Expand Up @@ -789,7 +789,7 @@ let () =
}]));
test "dict array array int - heterogenous structure" (fun () ->
try
let (_ : int array array Js_dict.t) =
let (_ : int array array Js.Dict.t) =
(dict (array (array int)))
(parseOrRaise
{| { "a": [[1, 2], [true]], "b": [[4], [5, 6]] } |})
Expand All @@ -805,7 +805,7 @@ let () =
pass);
test "dict array array int - heterogenous structure 2" (fun () ->
try
let (_ : int array array Js_dict.t) =
let (_ : int array array Js.Dict.t) =
(dict (array (array int)))
(parseOrRaise {| { "a": [[1, 2], "foo"], "b": [[4], [5, 6]] } |})
in
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Json_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let _ =

test "error" (fun () ->
try
let (_ : Js_json.t) = parseOrRaise "{" in
let (_ : Js.Json.t) = parseOrRaise "{" in
fail "should throw"
with ParseError "Unexpected end of JSON input" -> pass));

Expand Down
4 changes: 3 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
(library
(name json)
(public_name melange-json)
(modes melange))
(modes melange)
(preprocess
(pps melange.ppx)))

0 comments on commit bfeb902

Please sign in to comment.