Skip to content

Commit 7fea02a

Browse files
committed
add test for filtering annotations by tag
1 parent d3cbf35 commit 7fea02a

File tree

4 files changed

+348
-0
lines changed

4 files changed

+348
-0
lines changed

atdgen/test/dune

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,21 @@
258258
(package atdgen)
259259
(action (diff test_annot_error.expected.stdout test_annot_error.stdout)))
260260

261+
(rule
262+
(targets test_annot_tags_j.ml test_annot_tags_j.mli)
263+
(deps test_annot_tags.atd)
264+
(action (run %{bin:atdgen} -tag=melange -j -j-std %{deps})))
265+
266+
(rule
267+
(alias runtest)
268+
(package atdgen)
269+
(action (diff test_annot_tags_j.expected.ml test_annot_tags_j.ml)))
270+
271+
(rule
272+
(alias runtest)
273+
(package atdgen)
274+
(action (diff test_annot_tags_j.expected.mli test_annot_tags_j.mli)))
275+
261276
;; inline records are not allowed within poly variant, but allowed in classic
262277

263278
(rule

atdgen/test/test_annot_tags.atd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type t = {
2+
id : int;
3+
always_array : string list <ocaml repr="array">;
4+
melange_array : string list <ocaml repr="array" tag="melange" tag="ml">;
5+
ml_array : string list <ocaml repr="array" tag="ml">;
6+
}
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
(* Auto-generated from "test_annot_tags.atd" *)
2+
[@@@ocaml.warning "-27-32-33-35-39"]
3+
4+
type t = Test_annot_tags_t.t = {
5+
id: int;
6+
always_array: string Atdgen_runtime.Util.ocaml_array;
7+
melange_array: string Atdgen_runtime.Util.ocaml_array;
8+
ml_array: string list
9+
}
10+
11+
let write__x_f5dfc61 = (
12+
Atdgen_runtime.Oj_run.write_array (
13+
Yojson.Safe.write_string
14+
)
15+
)
16+
let string_of__x_f5dfc61 ?(len = 1024) x =
17+
let ob = Buffer.create len in
18+
write__x_f5dfc61 ob x;
19+
Buffer.contents ob
20+
let read__x_f5dfc61 = (
21+
Atdgen_runtime.Oj_run.read_array (
22+
Atdgen_runtime.Oj_run.read_string
23+
)
24+
)
25+
let _x_f5dfc61_of_string s =
26+
read__x_f5dfc61 (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
27+
let write__x_20d39e2 = (
28+
Atdgen_runtime.Oj_run.write_array (
29+
Yojson.Safe.write_string
30+
)
31+
)
32+
let string_of__x_20d39e2 ?(len = 1024) x =
33+
let ob = Buffer.create len in
34+
write__x_20d39e2 ob x;
35+
Buffer.contents ob
36+
let read__x_20d39e2 = (
37+
Atdgen_runtime.Oj_run.read_array (
38+
Atdgen_runtime.Oj_run.read_string
39+
)
40+
)
41+
let _x_20d39e2_of_string s =
42+
read__x_20d39e2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
43+
let write__string_list = (
44+
Atdgen_runtime.Oj_run.write_list (
45+
Yojson.Safe.write_string
46+
)
47+
)
48+
let string_of__string_list ?(len = 1024) x =
49+
let ob = Buffer.create len in
50+
write__string_list ob x;
51+
Buffer.contents ob
52+
let read__string_list = (
53+
Atdgen_runtime.Oj_run.read_list (
54+
Atdgen_runtime.Oj_run.read_string
55+
)
56+
)
57+
let _string_list_of_string s =
58+
read__string_list (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
59+
let write_t : _ -> t -> _ = (
60+
fun ob (x : t) ->
61+
Buffer.add_char ob '{';
62+
let is_first = ref true in
63+
if !is_first then
64+
is_first := false
65+
else
66+
Buffer.add_char ob ',';
67+
Buffer.add_string ob "\"id\":";
68+
(
69+
Yojson.Safe.write_int
70+
)
71+
ob x.id;
72+
if !is_first then
73+
is_first := false
74+
else
75+
Buffer.add_char ob ',';
76+
Buffer.add_string ob "\"always_array\":";
77+
(
78+
write__x_20d39e2
79+
)
80+
ob x.always_array;
81+
if !is_first then
82+
is_first := false
83+
else
84+
Buffer.add_char ob ',';
85+
Buffer.add_string ob "\"melange_array\":";
86+
(
87+
write__x_f5dfc61
88+
)
89+
ob x.melange_array;
90+
if !is_first then
91+
is_first := false
92+
else
93+
Buffer.add_char ob ',';
94+
Buffer.add_string ob "\"ml_array\":";
95+
(
96+
write__string_list
97+
)
98+
ob x.ml_array;
99+
Buffer.add_char ob '}';
100+
)
101+
let string_of_t ?(len = 1024) x =
102+
let ob = Buffer.create len in
103+
write_t ob x;
104+
Buffer.contents ob
105+
let read_t = (
106+
fun p lb ->
107+
Yojson.Safe.read_space p lb;
108+
Yojson.Safe.read_lcurl p lb;
109+
let field_id = ref (None) in
110+
let field_always_array = ref (None) in
111+
let field_melange_array = ref (None) in
112+
let field_ml_array = ref (None) in
113+
try
114+
Yojson.Safe.read_space p lb;
115+
Yojson.Safe.read_object_end lb;
116+
Yojson.Safe.read_space p lb;
117+
let f =
118+
fun s pos len ->
119+
if pos < 0 || len < 0 || pos + len > String.length s then
120+
invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len);
121+
match len with
122+
| 2 -> (
123+
if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then (
124+
0
125+
)
126+
else (
127+
-1
128+
)
129+
)
130+
| 8 -> (
131+
if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'l' && String.unsafe_get s (pos+2) = '_' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'y' then (
132+
3
133+
)
134+
else (
135+
-1
136+
)
137+
)
138+
| 12 -> (
139+
if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'l' && String.unsafe_get s (pos+2) = 'w' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'r' && String.unsafe_get s (pos+9) = 'r' && String.unsafe_get s (pos+10) = 'a' && String.unsafe_get s (pos+11) = 'y' then (
140+
1
141+
)
142+
else (
143+
-1
144+
)
145+
)
146+
| 13 -> (
147+
if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'g' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'r' && String.unsafe_get s (pos+10) = 'r' && String.unsafe_get s (pos+11) = 'a' && String.unsafe_get s (pos+12) = 'y' then (
148+
2
149+
)
150+
else (
151+
-1
152+
)
153+
)
154+
| _ -> (
155+
-1
156+
)
157+
in
158+
let i = Yojson.Safe.map_ident p f lb in
159+
Atdgen_runtime.Oj_run.read_until_field_value p lb;
160+
(
161+
match i with
162+
| 0 ->
163+
field_id := (
164+
Some (
165+
(
166+
Atdgen_runtime.Oj_run.read_int
167+
) p lb
168+
)
169+
);
170+
| 1 ->
171+
field_always_array := (
172+
Some (
173+
(
174+
read__x_20d39e2
175+
) p lb
176+
)
177+
);
178+
| 2 ->
179+
field_melange_array := (
180+
Some (
181+
(
182+
read__x_f5dfc61
183+
) p lb
184+
)
185+
);
186+
| 3 ->
187+
field_ml_array := (
188+
Some (
189+
(
190+
read__string_list
191+
) p lb
192+
)
193+
);
194+
| _ -> (
195+
Yojson.Safe.skip_json p lb
196+
)
197+
);
198+
while true do
199+
Yojson.Safe.read_space p lb;
200+
Yojson.Safe.read_object_sep p lb;
201+
Yojson.Safe.read_space p lb;
202+
let f =
203+
fun s pos len ->
204+
if pos < 0 || len < 0 || pos + len > String.length s then
205+
invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len);
206+
match len with
207+
| 2 -> (
208+
if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then (
209+
0
210+
)
211+
else (
212+
-1
213+
)
214+
)
215+
| 8 -> (
216+
if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'l' && String.unsafe_get s (pos+2) = '_' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'y' then (
217+
3
218+
)
219+
else (
220+
-1
221+
)
222+
)
223+
| 12 -> (
224+
if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'l' && String.unsafe_get s (pos+2) = 'w' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'r' && String.unsafe_get s (pos+9) = 'r' && String.unsafe_get s (pos+10) = 'a' && String.unsafe_get s (pos+11) = 'y' then (
225+
1
226+
)
227+
else (
228+
-1
229+
)
230+
)
231+
| 13 -> (
232+
if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'g' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'r' && String.unsafe_get s (pos+10) = 'r' && String.unsafe_get s (pos+11) = 'a' && String.unsafe_get s (pos+12) = 'y' then (
233+
2
234+
)
235+
else (
236+
-1
237+
)
238+
)
239+
| _ -> (
240+
-1
241+
)
242+
in
243+
let i = Yojson.Safe.map_ident p f lb in
244+
Atdgen_runtime.Oj_run.read_until_field_value p lb;
245+
(
246+
match i with
247+
| 0 ->
248+
field_id := (
249+
Some (
250+
(
251+
Atdgen_runtime.Oj_run.read_int
252+
) p lb
253+
)
254+
);
255+
| 1 ->
256+
field_always_array := (
257+
Some (
258+
(
259+
read__x_20d39e2
260+
) p lb
261+
)
262+
);
263+
| 2 ->
264+
field_melange_array := (
265+
Some (
266+
(
267+
read__x_f5dfc61
268+
) p lb
269+
)
270+
);
271+
| 3 ->
272+
field_ml_array := (
273+
Some (
274+
(
275+
read__string_list
276+
) p lb
277+
)
278+
);
279+
| _ -> (
280+
Yojson.Safe.skip_json p lb
281+
)
282+
);
283+
done;
284+
assert false;
285+
with Yojson.End_of_object -> (
286+
(
287+
{
288+
id = (match !field_id with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "id");
289+
always_array = (match !field_always_array with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "always_array");
290+
melange_array = (match !field_melange_array with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "melange_array");
291+
ml_array = (match !field_ml_array with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "ml_array");
292+
}
293+
: t)
294+
)
295+
)
296+
let t_of_string s =
297+
read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(* Auto-generated from "test_annot_tags.atd" *)
2+
[@@@ocaml.warning "-27-32-33-35-39"]
3+
4+
type t = Test_annot_tags_t.t = {
5+
id: int;
6+
always_array: string Atdgen_runtime.Util.ocaml_array;
7+
melange_array: string Atdgen_runtime.Util.ocaml_array;
8+
ml_array: string list
9+
}
10+
11+
val write_t :
12+
Buffer.t -> t -> unit
13+
(** Output a JSON value of type {!type:t}. *)
14+
15+
val string_of_t :
16+
?len:int -> t -> string
17+
(** Serialize a value of type {!type:t}
18+
into a JSON string.
19+
@param len specifies the initial length
20+
of the buffer used internally.
21+
Default: 1024. *)
22+
23+
val read_t :
24+
Yojson.Safe.lexer_state -> Lexing.lexbuf -> t
25+
(** Input JSON data of type {!type:t}. *)
26+
27+
val t_of_string :
28+
string -> t
29+
(** Deserialize JSON data of type {!type:t}. *)
30+

0 commit comments

Comments
 (0)