1943 lines
24 KiB
Zig
1943 lines
24 KiB
Zig
// RFC 8529 conformance tests.
|
||
//
|
||
// Tests are taken from https://github.com/nst/JSONTestSuite
|
||
// Read also http://seriot.ch/parsing_json.php for a good overview.
|
||
|
||
const std = @import("index.zig");
|
||
|
||
fn ok(comptime s: []const u8) void {
|
||
std.debug.assert(std.json.validate(s));
|
||
}
|
||
|
||
fn err(comptime s: []const u8) void {
|
||
std.debug.assert(!std.json.validate(s));
|
||
}
|
||
|
||
fn any(comptime s: []const u8) void {
|
||
std.debug.assert(true);
|
||
}
|
||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
||
test "y_array_arraysWithSpaces" {
|
||
ok(
|
||
\\[[] ]
|
||
);
|
||
}
|
||
|
||
test "y_array_empty" {
|
||
ok(
|
||
\\[]
|
||
);
|
||
}
|
||
|
||
test "y_array_empty-string" {
|
||
ok(
|
||
\\[""]
|
||
);
|
||
}
|
||
|
||
test "y_array_ending_with_newline" {
|
||
ok(
|
||
\\["a"]
|
||
);
|
||
}
|
||
|
||
test "y_array_false" {
|
||
ok(
|
||
\\[false]
|
||
);
|
||
}
|
||
|
||
test "y_array_heterogeneous" {
|
||
ok(
|
||
\\[null, 1, "1", {}]
|
||
);
|
||
}
|
||
|
||
test "y_array_null" {
|
||
ok(
|
||
\\[null]
|
||
);
|
||
}
|
||
|
||
test "y_array_with_1_and_newline" {
|
||
ok(
|
||
\\[1
|
||
\\]
|
||
);
|
||
}
|
||
|
||
test "y_array_with_leading_space" {
|
||
ok(
|
||
\\ [1]
|
||
);
|
||
}
|
||
|
||
test "y_array_with_several_null" {
|
||
ok(
|
||
\\[1,null,null,null,2]
|
||
);
|
||
}
|
||
|
||
test "y_array_with_trailing_space" {
|
||
ok(
|
||
"[2] "
|
||
);
|
||
}
|
||
|
||
test "y_number_0e+1" {
|
||
ok(
|
||
\\[0e+1]
|
||
);
|
||
}
|
||
|
||
test "y_number_0e1" {
|
||
ok(
|
||
\\[0e1]
|
||
);
|
||
}
|
||
|
||
test "y_number_after_space" {
|
||
ok(
|
||
\\[ 4]
|
||
);
|
||
}
|
||
|
||
test "y_number_double_close_to_zero" {
|
||
ok(
|
||
\\[-0.000000000000000000000000000000000000000000000000000000000000000000000000000001]
|
||
);
|
||
}
|
||
|
||
test "y_number_int_with_exp" {
|
||
ok(
|
||
\\[20e1]
|
||
);
|
||
}
|
||
|
||
test "y_number" {
|
||
ok(
|
||
\\[123e65]
|
||
);
|
||
}
|
||
|
||
test "y_number_minus_zero" {
|
||
ok(
|
||
\\[-0]
|
||
);
|
||
}
|
||
|
||
test "y_number_negative_int" {
|
||
ok(
|
||
\\[-123]
|
||
);
|
||
}
|
||
|
||
test "y_number_negative_one" {
|
||
ok(
|
||
\\[-1]
|
||
);
|
||
}
|
||
|
||
test "y_number_negative_zero" {
|
||
ok(
|
||
\\[-0]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_capital_e" {
|
||
ok(
|
||
\\[1E22]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_capital_e_neg_exp" {
|
||
ok(
|
||
\\[1E-2]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_capital_e_pos_exp" {
|
||
ok(
|
||
\\[1E+2]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_exponent" {
|
||
ok(
|
||
\\[123e45]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_fraction_exponent" {
|
||
ok(
|
||
\\[123.456e78]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_neg_exp" {
|
||
ok(
|
||
\\[1e-2]
|
||
);
|
||
}
|
||
|
||
test "y_number_real_pos_exponent" {
|
||
ok(
|
||
\\[1e+2]
|
||
);
|
||
}
|
||
|
||
test "y_number_simple_int" {
|
||
ok(
|
||
\\[123]
|
||
);
|
||
}
|
||
|
||
test "y_number_simple_real" {
|
||
ok(
|
||
\\[123.456789]
|
||
);
|
||
}
|
||
|
||
test "y_object_basic" {
|
||
ok(
|
||
\\{"asd":"sdf"}
|
||
);
|
||
}
|
||
|
||
test "y_object_duplicated_key_and_value" {
|
||
ok(
|
||
\\{"a":"b","a":"b"}
|
||
);
|
||
}
|
||
|
||
test "y_object_duplicated_key" {
|
||
ok(
|
||
\\{"a":"b","a":"c"}
|
||
);
|
||
}
|
||
|
||
test "y_object_empty" {
|
||
ok(
|
||
\\{}
|
||
);
|
||
}
|
||
|
||
test "y_object_empty_key" {
|
||
ok(
|
||
\\{"":0}
|
||
);
|
||
}
|
||
|
||
test "y_object_escaped_null_in_key" {
|
||
ok(
|
||
\\{"foo\u0000bar": 42}
|
||
);
|
||
}
|
||
|
||
test "y_object_extreme_numbers" {
|
||
ok(
|
||
\\{ "min": -1.0e+28, "max": 1.0e+28 }
|
||
);
|
||
}
|
||
|
||
test "y_object" {
|
||
ok(
|
||
\\{"asd":"sdf", "dfg":"fgh"}
|
||
);
|
||
}
|
||
|
||
test "y_object_long_strings" {
|
||
ok(
|
||
\\{"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
||
);
|
||
}
|
||
|
||
test "y_object_simple" {
|
||
ok(
|
||
\\{"a":[]}
|
||
);
|
||
}
|
||
|
||
test "y_object_string_unicode" {
|
||
ok(
|
||
\\{"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" }
|
||
);
|
||
}
|
||
|
||
test "y_object_with_newlines" {
|
||
ok(
|
||
\\{
|
||
\\"a": "b"
|
||
\\}
|
||
);
|
||
}
|
||
|
||
test "y_string_1_2_3_bytes_UTF-8_sequences" {
|
||
ok(
|
||
\\["\u0060\u012a\u12AB"]
|
||
);
|
||
}
|
||
|
||
test "y_string_accepted_surrogate_pair" {
|
||
ok(
|
||
\\["\uD801\udc37"]
|
||
);
|
||
}
|
||
|
||
test "y_string_accepted_surrogate_pairs" {
|
||
ok(
|
||
\\["\ud83d\ude39\ud83d\udc8d"]
|
||
);
|
||
}
|
||
|
||
test "y_string_allowed_escapes" {
|
||
ok(
|
||
\\["\"\\\/\b\f\n\r\t"]
|
||
);
|
||
}
|
||
|
||
test "y_string_backslash_and_u_escaped_zero" {
|
||
ok(
|
||
\\["\\u0000"]
|
||
);
|
||
}
|
||
|
||
test "y_string_backslash_doublequotes" {
|
||
ok(
|
||
\\["\""]
|
||
);
|
||
}
|
||
|
||
test "y_string_comments" {
|
||
ok(
|
||
\\["a/*b*/c/*d//e"]
|
||
);
|
||
}
|
||
|
||
test "y_string_double_escape_a" {
|
||
ok(
|
||
\\["\\a"]
|
||
);
|
||
}
|
||
|
||
test "y_string_double_escape_n" {
|
||
ok(
|
||
\\["\\n"]
|
||
);
|
||
}
|
||
|
||
test "y_string_escaped_control_character" {
|
||
ok(
|
||
\\["\u0012"]
|
||
);
|
||
}
|
||
|
||
test "y_string_escaped_noncharacter" {
|
||
ok(
|
||
\\["\uFFFF"]
|
||
);
|
||
}
|
||
|
||
test "y_string_in_array" {
|
||
ok(
|
||
\\["asd"]
|
||
);
|
||
}
|
||
|
||
test "y_string_in_array_with_leading_space" {
|
||
ok(
|
||
\\[ "asd"]
|
||
);
|
||
}
|
||
|
||
test "y_string_last_surrogates_1_and_2" {
|
||
ok(
|
||
\\["\uDBFF\uDFFF"]
|
||
);
|
||
}
|
||
|
||
test "y_string_nbsp_uescaped" {
|
||
ok(
|
||
\\["new\u00A0line"]
|
||
);
|
||
}
|
||
|
||
test "y_string_nonCharacterInUTF-8_U+10FFFF" {
|
||
ok(
|
||
\\[""]
|
||
);
|
||
}
|
||
|
||
test "y_string_nonCharacterInUTF-8_U+FFFF" {
|
||
ok(
|
||
\\[""]
|
||
);
|
||
}
|
||
|
||
test "y_string_null_escape" {
|
||
ok(
|
||
\\["\u0000"]
|
||
);
|
||
}
|
||
|
||
test "y_string_one-byte-utf-8" {
|
||
ok(
|
||
\\["\u002c"]
|
||
);
|
||
}
|
||
|
||
test "y_string_pi" {
|
||
ok(
|
||
\\["π"]
|
||
);
|
||
}
|
||
|
||
test "y_string_reservedCharacterInUTF-8_U+1BFFF" {
|
||
ok(
|
||
\\[""]
|
||
);
|
||
}
|
||
|
||
test "y_string_simple_ascii" {
|
||
ok(
|
||
\\["asd "]
|
||
);
|
||
}
|
||
|
||
test "y_string_space" {
|
||
ok(
|
||
\\" "
|
||
);
|
||
}
|
||
|
||
test "y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF" {
|
||
ok(
|
||
\\["\uD834\uDd1e"]
|
||
);
|
||
}
|
||
|
||
test "y_string_three-byte-utf-8" {
|
||
ok(
|
||
\\["\u0821"]
|
||
);
|
||
}
|
||
|
||
test "y_string_two-byte-utf-8" {
|
||
ok(
|
||
\\["\u0123"]
|
||
);
|
||
}
|
||
|
||
test "y_string_u+2028_line_sep" {
|
||
ok(
|
||
\\["
"]
|
||
);
|
||
}
|
||
|
||
test "y_string_u+2029_par_sep" {
|
||
ok(
|
||
\\["
"]
|
||
);
|
||
}
|
||
|
||
test "y_string_uescaped_newline" {
|
||
ok(
|
||
\\["new\u000Aline"]
|
||
);
|
||
}
|
||
|
||
test "y_string_uEscape" {
|
||
ok(
|
||
\\["\u0061\u30af\u30EA\u30b9"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unescaped_char_delete" {
|
||
ok(
|
||
\\[""]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_2" {
|
||
ok(
|
||
\\["⍂㈴⍂"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicodeEscapedBackslash" {
|
||
ok(
|
||
\\["\u005C"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_escaped_double_quote" {
|
||
ok(
|
||
\\["\u0022"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode" {
|
||
ok(
|
||
\\["\uA66D"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_U+10FFFE_nonchar" {
|
||
ok(
|
||
\\["\uDBFF\uDFFE"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_U+1FFFE_nonchar" {
|
||
ok(
|
||
\\["\uD83F\uDFFE"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_U+200B_ZERO_WIDTH_SPACE" {
|
||
ok(
|
||
\\["\u200B"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_U+2064_invisible_plus" {
|
||
ok(
|
||
\\["\u2064"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_U+FDD0_nonchar" {
|
||
ok(
|
||
\\["\uFDD0"]
|
||
);
|
||
}
|
||
|
||
test "y_string_unicode_U+FFFE_nonchar" {
|
||
ok(
|
||
\\["\uFFFE"]
|
||
);
|
||
}
|
||
|
||
test "y_string_utf8" {
|
||
ok(
|
||
\\["€𝄞"]
|
||
);
|
||
}
|
||
|
||
test "y_string_with_del_character" {
|
||
ok(
|
||
\\["aa"]
|
||
);
|
||
}
|
||
|
||
test "y_structure_lonely_false" {
|
||
ok(
|
||
\\false
|
||
);
|
||
}
|
||
|
||
test "y_structure_lonely_int" {
|
||
ok(
|
||
\\42
|
||
);
|
||
}
|
||
|
||
test "y_structure_lonely_negative_real" {
|
||
ok(
|
||
\\-0.1
|
||
);
|
||
}
|
||
|
||
test "y_structure_lonely_null" {
|
||
ok(
|
||
\\null
|
||
);
|
||
}
|
||
|
||
test "y_structure_lonely_string" {
|
||
ok(
|
||
\\"asd"
|
||
);
|
||
}
|
||
|
||
test "y_structure_lonely_true" {
|
||
ok(
|
||
\\true
|
||
);
|
||
}
|
||
|
||
test "y_structure_string_empty" {
|
||
ok(
|
||
\\""
|
||
);
|
||
}
|
||
|
||
test "y_structure_trailing_newline" {
|
||
ok(
|
||
\\["a"]
|
||
);
|
||
}
|
||
|
||
test "y_structure_true_in_array" {
|
||
ok(
|
||
\\[true]
|
||
);
|
||
}
|
||
|
||
test "y_structure_whitespace_array" {
|
||
ok(
|
||
" [] "
|
||
);
|
||
}
|
||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
||
test "n_array_1_true_without_comma" {
|
||
err(
|
||
\\[1 true]
|
||
);
|
||
}
|
||
|
||
test "n_array_a_invalid_utf8" {
|
||
err(
|
||
\\[aå]
|
||
);
|
||
}
|
||
|
||
test "n_array_colon_instead_of_comma" {
|
||
err(
|
||
\\["": 1]
|
||
);
|
||
}
|
||
|
||
test "n_array_comma_after_close" {
|
||
//err(
|
||
// \\[""],
|
||
//);
|
||
}
|
||
|
||
test "n_array_comma_and_number" {
|
||
err(
|
||
\\[,1]
|
||
);
|
||
}
|
||
|
||
test "n_array_double_comma" {
|
||
err(
|
||
\\[1,,2]
|
||
);
|
||
}
|
||
|
||
test "n_array_double_extra_comma" {
|
||
err(
|
||
\\["x",,]
|
||
);
|
||
}
|
||
|
||
test "n_array_extra_close" {
|
||
err(
|
||
\\["x"]]
|
||
);
|
||
}
|
||
|
||
test "n_array_extra_comma" {
|
||
//err(
|
||
// \\["",]
|
||
//);
|
||
}
|
||
|
||
test "n_array_incomplete_invalid_value" {
|
||
err(
|
||
\\[x
|
||
);
|
||
}
|
||
|
||
test "n_array_incomplete" {
|
||
err(
|
||
\\["x"
|
||
);
|
||
}
|
||
|
||
test "n_array_inner_array_no_comma" {
|
||
err(
|
||
\\[3[4]]
|
||
);
|
||
}
|
||
|
||
test "n_array_invalid_utf8" {
|
||
err(
|
||
\\[ÿ]
|
||
);
|
||
}
|
||
|
||
test "n_array_items_separated_by_semicolon" {
|
||
err(
|
||
\\[1:2]
|
||
);
|
||
}
|
||
|
||
test "n_array_just_comma" {
|
||
err(
|
||
\\[,]
|
||
);
|
||
}
|
||
|
||
test "n_array_just_minus" {
|
||
err(
|
||
\\[-]
|
||
);
|
||
}
|
||
|
||
test "n_array_missing_value" {
|
||
err(
|
||
\\[ , ""]
|
||
);
|
||
}
|
||
|
||
test "n_array_newlines_unclosed" {
|
||
err(
|
||
\\["a",
|
||
\\4
|
||
\\,1,
|
||
);
|
||
}
|
||
|
||
|
||
test "n_array_number_and_comma" {
|
||
err(
|
||
\\[1,]
|
||
);
|
||
}
|
||
|
||
test "n_array_number_and_several_commas" {
|
||
err(
|
||
\\[1,,]
|
||
);
|
||
}
|
||
|
||
test "n_array_spaces_vertical_tab_formfeed" {
|
||
err(
|
||
\\["a"\f]
|
||
);
|
||
}
|
||
|
||
test "n_array_star_inside" {
|
||
err(
|
||
\\[*]
|
||
);
|
||
}
|
||
|
||
test "n_array_unclosed" {
|
||
err(
|
||
\\[""
|
||
);
|
||
}
|
||
|
||
test "n_array_unclosed_trailing_comma" {
|
||
err(
|
||
\\[1,
|
||
);
|
||
}
|
||
|
||
test "n_array_unclosed_with_new_lines" {
|
||
err(
|
||
\\[1,
|
||
\\1
|
||
\\,1
|
||
);
|
||
}
|
||
|
||
test "n_array_unclosed_with_object_inside" {
|
||
err(
|
||
\\[{}
|
||
);
|
||
}
|
||
|
||
test "n_incomplete_false" {
|
||
err(
|
||
\\[fals]
|
||
);
|
||
}
|
||
|
||
test "n_incomplete_null" {
|
||
err(
|
||
\\[nul]
|
||
);
|
||
}
|
||
|
||
test "n_incomplete_true" {
|
||
err(
|
||
\\[tru]
|
||
);
|
||
}
|
||
|
||
test "n_multidigit_number_then_00" {
|
||
err(
|
||
\\123 |