Skip to content

Commit 48abda6

Browse files
committed
add failing test for array
1 parent ac0f795 commit 48abda6

File tree

3 files changed

+16
-72
lines changed

3 files changed

+16
-72
lines changed

ppx/test/example.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ('a, 'b) p2 = A of 'a | B of 'b [@@deriving json]
2121
type allow_extra_fields = {a: int} [@@deriving json] [@@json.allow_extra_fields]
2222
type allow_extra_fields2 = A of {a: int} [@json.allow_extra_fields] [@@deriving json]
2323
type drop_default_option = { a: int; b_opt: int option; [@option] [@json.drop_default] } [@@deriving json]
24+
type array_list = { a: int array; b: int list} [@@deriving json]
2425

2526
type json = Ppx_deriving_json_runtime.t
2627
type of_json = C : string * (json -> 'a) * ('a -> json) * 'a -> of_json
@@ -55,6 +56,7 @@ let of_json_cases = [
5556
C ({|["A",{"a":1,"b":2}]|}, allow_extra_fields2_of_json, allow_extra_fields2_to_json, A {a=1});
5657
C ({|{"a":1}|}, drop_default_option_of_json, drop_default_option_to_json, {a=1; b_opt=None});
5758
C ({|{"a":1,"b_opt":2}|}, drop_default_option_of_json, drop_default_option_to_json, {a=1; b_opt=Some 2});
59+
C ({|{"a":[1],"b":[2]}|}, array_list_of_json, array_list_to_json, {a=[|1|]; b=[2]});
5860
]
5961
let run' (C (data, of_json, to_json, v)) =
6062
print_endline (Printf.sprintf "JSON DATA: %s" data);

ppx/test/ppx_deriving_json_js.e2e.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
JSON REPRINT: {"a":1}
8888
JSON DATA: {"a":1,"b_opt":2}
8989
JSON REPRINT: {"a":1,"b_opt":2}
90+
JSON DATA: {"a":[1],"b":[2]}
91+
JSON REPRINT: {"a":[1],"b":[2]}
9092
*** json_string deriver tests ***
9193
** To_json_string **
9294
A 42 -> ["A",42]

ppx/test/ppx_deriving_json_native.e2e.t

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,77 +15,17 @@
1515
> ' >> main.ml
1616

1717
$ dune build ./main.exe
18+
File "example.ml", line 24, characters 27-32:
19+
24 | type array_list = { a: int array; b: int list} [@@deriving json]
20+
^^^^^
21+
Error: Unbound value array_of_json
22+
Hint: Did you mean param_of_json?
23+
[1]
1824

1925
$ dune exec ./main.exe
20-
JSON DATA: 1
21-
JSON REPRINT: 1
22-
JSON DATA: "9223372036854775807"
23-
JSON REPRINT: "9223372036854775807"
24-
JSON DATA: 1.1
25-
JSON REPRINT: 1.1
26-
JSON DATA: 1.0
27-
JSON REPRINT: 1.0
28-
JSON DATA: 42
29-
JSON REPRINT: 42.0
30-
JSON DATA: "OK"
31-
JSON REPRINT: "OK"
32-
JSON DATA: "some"
33-
JSON REPRINT: "some"
34-
JSON DATA: ["Ok", 1]
35-
JSON REPRINT: ["Ok",1]
36-
JSON DATA: ["Error", "oops"]
37-
JSON REPRINT: ["Error","oops"]
38-
JSON DATA: [42, "works"]
39-
JSON REPRINT: [42,"works"]
40-
JSON DATA: {"name":"N","age":1}
41-
JSON REPRINT: {"name":"N","age":1}
42-
JSON DATA: ["A"]
43-
JSON REPRINT: ["A"]
44-
JSON DATA: ["B", 42]
45-
JSON REPRINT: ["B",42]
46-
JSON DATA: ["C", {"name": "cname"}]
47-
JSON REPRINT: ["C",{"name":"cname"}]
48-
JSON DATA: ["A"]
49-
JSON REPRINT: ["A"]
50-
JSON DATA: ["S2", 42, "hello"]
51-
JSON REPRINT: ["S2",42,"hello"]
52-
JSON DATA: ["B", 42]
53-
JSON REPRINT: ["B",42]
54-
JSON DATA: ["P2", 42, "hello"]
55-
JSON REPRINT: ["P2",42,"hello"]
56-
JSON DATA: ["Fix",["Fix",["Fix",["A"]]]]
57-
JSON REPRINT: ["Fix",["Fix",["Fix",["A"]]]]
58-
JSON DATA: ["Fix",["Fix",["Fix",["A"]]]]
59-
JSON REPRINT: ["Fix",["Fix",["Fix",["A"]]]]
60-
JSON DATA: {"my_name":"N","my_age":1}
61-
JSON REPRINT: {"my_name":"N","my_age":1}
62-
JSON DATA: {"my_name":"N"}
63-
JSON REPRINT: {"my_name":"N","my_age":100}
64-
JSON DATA: {}
65-
JSON REPRINT: {"k":null}
66-
JSON DATA: {"k":42}
67-
JSON REPRINT: {"k":42}
68-
JSON DATA: ["A",1]
69-
JSON REPRINT: ["A",1]
70-
JSON DATA: ["B","ok"]
71-
JSON REPRINT: ["B","ok"]
72-
JSON DATA: {"a":1,"b":2}
73-
JSON REPRINT: {"a":1}
74-
JSON DATA: ["A",{"a":1,"b":2}]
75-
JSON REPRINT: ["A",{"a":1}]
76-
JSON DATA: {"a":1}
77-
JSON REPRINT: {"a":1}
78-
JSON DATA: {"a":1,"b_opt":2}
79-
JSON REPRINT: {"a":1,"b_opt":2}
80-
*** json_string deriver tests ***
81-
** To_json_string **
82-
A 42 -> ["A",42]
83-
B false -> ["B",false]
84-
** Of_json_string **
85-
["A", 42] = A 42 -> true
86-
["B", false] = B false -> true
87-
** Json_string **
88-
A 42 -> ["A",42]
89-
B false -> ["B",false]
90-
["A", 42] = A 42 -> true
91-
["B", false] = B false -> true
26+
File "example.ml", line 24, characters 27-32:
27+
24 | type array_list = { a: int array; b: int list} [@@deriving json]
28+
^^^^^
29+
Error: Unbound value array_of_json
30+
Hint: Did you mean param_of_json?
31+
[1]

0 commit comments

Comments
 (0)