Skip to content

Commit

Permalink
Add a RFC 8259 compliance test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Rebours committed Feb 22, 2019
1 parent 5c00065 commit 9db28ca
Show file tree
Hide file tree
Showing 320 changed files with 385 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/compliance/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(executable
(name test)
(libraries
alcotest
yojson
)
)

(alias
(name compliance-tests)
(deps
(:test test.exe)
(glob_files test_cases/*)
)
(action (run %{test} --show-errors))
)
51 changes: 51 additions & 0 deletions test/compliance/test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
let test_cases_dir = "test_cases"

let test ~accepted ~rejected ~dir_name file_name =
try
let json = Yojson.Basic.from_file @@ Filename.concat dir_name file_name in
let pped = Yojson.Basic.show json in
accepted file_name pped
with
| Yojson.Json_error msg ->
rejected file_name msg

let pass = fun _ _ -> ()

let fail fmt filename v = Alcotest.failf fmt filename v

let test_parses =
test
~accepted:pass
~rejected:(fail "%s is valid JSON but failed with Json_error %s")

let test_rejects =
test
~accepted:(fail "%s is invalid JSON but parsed to %s")
~rejected:pass

let test_any =
test
~accepted:pass
~rejected:pass

let test_file ~dir_name file_name =
match file_name.[0] with
| 'y' -> test_parses ~dir_name file_name
| 'n' -> test_rejects ~dir_name file_name
| 'i' -> test_any ~dir_name file_name
| _ -> assert false

let basic =
let test_files = Array.to_list @@ Sys.readdir test_cases_dir in
let sorted = List.sort String.compare test_files in
List.rev_map
( fun base_name ->
(base_name, `Quick, fun () -> test_file ~dir_name:test_cases_dir base_name)
)
sorted

let () =
Alcotest.run
"RFC 8259 Compliance"
[ "Yojson.Basic", basic
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[123.456e-789]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_huge_exp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_neg_int_huge_exp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-1e+9999]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.5e+9999]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_real_neg_overflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-123123e100000]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_real_pos_overflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[123123e100000]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_real_underflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[123e-10000000]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_too_big_neg_int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-123123123123123123123123123123]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_number_too_big_pos_int.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[100000000000000000000]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-237462374673276894279832749832423479823246327846]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"\uDFAA":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uDADA"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uD888\u1234"]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["日ш�"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["���"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uD800\n"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uDd1ea"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uD800\uD800\n"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\ud800"]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_string_invalid_surrogate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\ud800abc"]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_string_invalid_utf-8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[""]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uDd1e\uD834"]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_string_iso_latin_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[""]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uDFAA"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[""]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["����"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["��"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["������"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["������"]
1 change: 1 addition & 0 deletions test/compliance/test_cases/i_string_truncated-utf-8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["��"]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1 true]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_a_invalid_utf8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[a�]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["": 1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_comma_after_close.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[""],
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_comma_and_number.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[,1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_double_comma.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1,,2]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_double_extra_comma.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["x",,]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_extra_close.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["x"]]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_extra_comma.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["",]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_incomplete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["x"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[3[4]]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_invalid_utf8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1:2]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_just_comma.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[,]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_just_minus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_missing_value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ , ""]
3 changes: 3 additions & 0 deletions test/compliance/test_cases/n_array_newlines_unclosed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
["a",
4
,1,
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_number_and_comma.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1,]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1,,]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[" a"\f]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_star_inside.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[*]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_array_unclosed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1,
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[1,
1
,1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{}
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_incomplete_false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[fals]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_incomplete_null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[nul]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_incomplete_true.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[tru]
Binary file not shown.
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_++.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[++1234]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_+1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[+1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_+Inf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[+Inf]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_-01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-01]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_-1.0..json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-1.0.]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_-2..json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-2.]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_-NaN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-NaN]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_.-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[.-1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_.2e-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[.2e-3]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0.1.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0.1.2]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0.3e+.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0.3e+]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0.3e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0.3e]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0.e1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0.e1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0_capital_E+.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0E+]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0_capital_E.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0E]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0e+.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0e+]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_0e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0e]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_1.0e+.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.0e+]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_1.0e-.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.0e-]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_1.0e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.0e]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_1_000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1 000.0]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_1eE2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1eE2]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_2.e+3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2.e+3]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_2.e-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2.e-3]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_2.e3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2.e3]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_9.e+.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[9.e+]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_Inf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Inf]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_NaN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[NaN]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_expression.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1+2]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_hex_1_digit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0x1]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_hex_2_digits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0x42]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_infinity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Infinity]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_invalid+-.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0e+-1]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-123.123foo]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[123�]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1e1�]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0�]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_minus_infinity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-Infinity]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-foo]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_minus_space_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[- 1]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-012]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-.123]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-1x]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1ea]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1e�]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.]
1 change: 1 addition & 0 deletions test/compliance/test_cases/n_number_starting_with_dot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[.123]
Loading

0 comments on commit 9db28ca

Please sign in to comment.