Commit 1dc95421 authored by Ralf Treinen's avatar Ralf Treinen

Update upstream source from tag 'upstream/3.1'

Update to upstream version '3.1'
with Debian dir 04c10f089c938af5c1fd01b6712e74a38a5bf169
parents 8cf64590 c8083f14
......@@ -2,6 +2,9 @@ language: c
env:
- OCAML=4.02.3
- OCAML=4.03.0
- OCAML=4.04.2
- OCAML=4.05.0
- OCAML=4.06.0
script:
- echo "yes" | sudo add-apt-repository ppa:avsm/ppa
- sudo apt-get update -qq
......
Changelog
=========
3.1
---
* Fix ppx_deriving_yojson.runtime META file
(#47)
Étienne Millon
* Support for inline records in variant types
(#50)
Gerd Stolpmann
* OCaml 4.06 compatibility
(#64, #66)
Leonid Rozenberg, Gabriel Scherer
3.0
---
* Use Result.result in generated code.
* Compatibility with statically linked ppx drivers.
* OCaml 4.03 compatibility.
2.3
---
......
......@@ -73,6 +73,16 @@ Variants (regular and polymorphic) are represented using arrays; the first eleme
[["A"],["B",42],["C",42,"foo"]]
```
Record variants are represented in the same way as if the nested structure was defined separately. For example:
```ocaml
# type v = X of { v: int } [@@deriving yojson];;
# print_endline (Yojson.Safe.to_string (v_to_yojson (X { v = 0 })));;
["X",{"v":0}]
```
Record variants are currently not supported for extensible variant types.
By default, objects are deserialized strictly; that is, all keys in the object have to correspond to fields of the record. Passing `strict = false` as an option to the deriver (i.e. `[@@deriving yojson { strict = false }]`) changes the behavior to ignore any unknown fields.
### Options
......
......@@ -3,3 +3,4 @@ true: warn(@5@8@10@11@12@14@23@24@26@29@40), bin_annot, safe_string, cppo_V_OCAM
"src": include
<src/*.{ml,mli,byte,native}>: package(ppx_tools.metaquot), package(ppx_deriving.api), package(result)
<src_test/*.{ml,byte,native}>: debug, package(result), package(oUnit), package(yojson), use_yojson
true: linkall
opam-version: "1.2"
name: "ppx_deriving_yojson"
version: "3.0"
version: "3.1"
maintainer: "whitequark <whitequark@whitequark.org>"
authors: [ "whitequark <whitequark@whitequark.org>" ]
license: "MIT"
......@@ -15,15 +15,17 @@ build: [
"native-dynlink=%{ocaml-native-dynlink}%"
]
build-test: [
"ocamlbuild" "-classic-display" "-use-ocamlfind" "src_test/test_ppx_yojson.byte" "--"
"ocamlbuild" "-classic-display" "-use-ocamlfind"
"src_test/test_ppx_yojson.byte" "--"
]
depends: [
"yojson"
"result"
"ppx_deriving" {>= "4.0" & < "5.0"}
"ocamlfind" {build}
"cppo" {build}
"ocamlfind" {build}
"ocamlbuild" {build}
"cppo" {build}
"cppo_ocamlbuild" {build}
"ounit" {test}
"ppx_import" {test & >= "1.1"}
]
......@@ -10,7 +10,7 @@ exists_if = "ppx_deriving_yojson.cma"
package "runtime" (
version = "%{version}%"
description = "Runtime components of [@@deriving yojson]"
requires = "yojson result"
requires = "yojson result ppx_deriving.runtime"
archive(byte) = "ppx_deriving_yojson_runtime.cma"
archive(byte, plugin) = "ppx_deriving_yojson_runtime.cma"
archive(native) = "ppx_deriving_yojson_runtime.cmxa"
......
This diff is collapsed.
......@@ -55,6 +55,10 @@ type v = A | B of int | C of int * string
[@@deriving show, yojson]
type r = { x : int; y : string }
[@@deriving show, yojson]
#if OCAML_VERSION >= (4, 03, 0)
type rv = RA | RB of int | RC of int * string | RD of { z : string }
[@@deriving show, yojson]
#endif
let test_unit ctxt =
assert_roundtrip pp_u u_to_yojson u_of_yojson
......@@ -176,6 +180,18 @@ let test_rec ctxt =
assert_roundtrip pp_r r_to_yojson r_of_yojson
{x=42; y="foo"} "{\"x\":42,\"y\":\"foo\"}"
#if OCAML_VERSION >= (4, 03, 0)
let test_recvar ctxt =
assert_roundtrip pp_rv rv_to_yojson rv_of_yojson
RA "[\"RA\"]";
assert_roundtrip pp_rv rv_to_yojson rv_of_yojson
(RB 42) "[\"RB\", 42]";
assert_roundtrip pp_rv rv_to_yojson rv_of_yojson
(RC(42, "foo")) "[\"RC\", 42, \"foo\"]";
assert_roundtrip pp_rv rv_to_yojson rv_of_yojson
(RD{z="foo"}) "[\"RD\", {\"z\": \"foo\"}]"
#endif
type geo = {
lat : float [@key "Latitude"] ;
lon : float [@key "Longitude"] ;
......@@ -359,6 +375,16 @@ let test_recursive ctxt =
assert_roundtrip pp_bar bar_to_yojson bar_of_yojson
{lhs="x"; rhs=42} "{\"lhs\":\"x\",\"rhs\":42}"
let test_int_redefined ctxt =
let module M = struct
type int = Break_things
let x = [%to_yojson: int] 1
end
in
let expected = `Int 1 in
assert_equal ~ctxt ~printer:show_json expected M.x
let suite = "Test ppx_yojson" >::: [
"test_unit" >:: test_unit;
"test_int" >:: test_int;
......@@ -376,6 +402,9 @@ let suite = "Test ppx_yojson" >::: [
"test_pvar" >:: test_pvar;
"test_var" >:: test_var;
"test_rec" >:: test_rec;
#if OCAML_VERSION >= (4, 03, 0)
"test_recvar" >:: test_recvar;
#endif
"test_key" >:: test_key;
"test_id" >:: test_id;
"test_custvar" >:: test_custvar;
......@@ -387,6 +416,7 @@ let suite = "Test ppx_yojson" >::: [
"test_nostrict" >:: test_nostrict;
"test_opentype" >:: test_opentype;
"test_recursive" >:: test_recursive;
"test_int_redefined" >:: test_int_redefined;
]
let _ =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment