Skip to content

Commit 1cf35a3

Browse files
committed
test for tupleN and empty_list
1 parent ef435ef commit 1cf35a3

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

test-yojson/main.ml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,47 @@ let yojson_basic_suite =
172172
Format.asprintf "@,@[%a@]" pp_error e )
173173
in
174174

175-
let tuple_helper_test =
176-
"Tuple helper"
175+
let tupleN_test =
176+
"TupleN"
177177
>:: fun _ ->
178178
let module M = struct
179179
type t2 = int * string
180180

181181
let t2_to_string ((i, s) : t2) = Printf.sprintf "(%i, %s)" i s
182182
end in
183183
let open M in
184-
let open TupleHelper in
185184
decoder_test
186185
()
187186
~decoder:(tuple2 int string)
188187
~input:{|[149, "my string"]|}
189188
~expected:(149, "my string")
190189
~printer:t2_to_string
191190
in
191+
let empty_list_test =
192+
"empty_list"
193+
>:: fun _ ->
194+
decoder_test
195+
()
196+
~decoder:empty_list
197+
~input:{|[]|}
198+
~expected:()
199+
~printer:(fun () -> Printf.sprintf "()")
200+
in
201+
let empty_list_nonempty_test =
202+
"empty_list_enforced"
203+
>:: fun _ ->
204+
let input = {|[1, 2]|} in
205+
let expected_error =
206+
let open Decoders in
207+
Error.make ~context:(`List [ `Int 1; `Int 2 ]) "Expected an empty list"
208+
in
209+
match decode_string empty_list input with
210+
| Ok _ ->
211+
assert_string "Expected an error"
212+
| Error error ->
213+
assert_equal expected_error error ~printer:(fun e ->
214+
Format.asprintf "@,@[%a@]" pp_error e )
215+
in
192216

193217
"Yojson.Basic"
194218
>::: [ list_string_test
@@ -197,7 +221,9 @@ let yojson_basic_suite =
197221
; mut_rec_test
198222
; string_or_floatlit_test
199223
; grouping_errors_test
200-
; tuple_helper_test
224+
; tupleN_test
225+
; empty_list_test
226+
; empty_list_nonempty_test
201227
]
202228

203229

0 commit comments

Comments
 (0)