#![allow(non_snake_case)] use jsn::TokenReader; use std::fs; use std::path; #[test] fn test_files() { let files = ["twitter.json", "citm_catalog.json", "canada.json"]; for file in files { let path = path::Path::new("tests/files").join(file); let input = fs::read(path).expect("testfile should exist"); let mut iter = TokenReader::new(input.as_slice()).into_iter(); let result = iter.dry_run(); assert!( result.is_ok(), "failed to parse {}\n{:?}", file, result.unwrap_err() ); } } macro_rules! pass { ($file:ident) => { #[test] fn $file() { let path = std::path::Path::new("tests/json_test_suite").join(stringify!($file)); let input = std::fs::read(path).expect("testfile should exist"); let mut iter = jsn::TokenReader::new(input.as_slice()).into_iter(); let result = iter.dry_run(); assert!(result.is_ok()); } }; } macro_rules! fail { ($file:ident) => { #[test] fn $file() { let path = std::path::Path::new("tests/json_test_suite").join(stringify!($file)); let input = std::fs::read(path).expect("testfile should exist"); let mut iter = jsn::TokenReader::new(input.as_slice()).into_iter(); let result = iter.dry_run(); assert!(result.is_err()); } }; } fail!(n_array_1_true_without_comma); fail!(n_array_a_invalid_utf8); fail!(n_array_colon_instead_of_comma); fail!(n_array_comma_after_close); fail!(n_array_comma_and_number); fail!(n_array_double_comma); fail!(n_array_double_extra_comma); fail!(n_array_extra_close); fail!(n_array_extra_comma); fail!(n_array_incomplete); fail!(n_array_incomplete_invalid_value); fail!(n_array_inner_array_no_comma); fail!(n_array_invalid_utf8); fail!(n_array_items_separated_by_semicolon); fail!(n_array_just_comma); fail!(n_array_just_minus); fail!(n_array_missing_value); fail!(n_array_newlines_unclosed); fail!(n_array_number_and_comma); fail!(n_array_number_and_several_commas); fail!(n_array_spaces_vertical_tab_formfeed); fail!(n_array_star_inside); fail!(n_array_unclosed); fail!(n_array_unclosed_trailing_comma); fail!(n_array_unclosed_with_new_lines); fail!(n_array_unclosed_with_object_inside); fail!(n_incomplete_false); fail!(n_incomplete_null); fail!(n_incomplete_true); fail!(n_multidigit_number_then_00); fail!(n_number_plusplus); fail!(n_number_plus1); fail!(n_number_plusInf); fail!(n_number__1_dot_0_dot_); fail!(n_number__01); fail!(n_number__2_dot_); fail!(n_number__NaN); fail!(n_number__dot__1); fail!(n_number__dot_2e_3); fail!(n_number_0_dot_1_dot_2); fail!(n_number_0_dot_3eplus); fail!(n_number_0_dot_3e); fail!(n_number_0_dot_e1); fail!(n_number_0_capital_Eplus); fail!(n_number_0_capital_E); fail!(n_number_0eplus); fail!(n_number_0e); fail!(n_number_1_dot_0eplus); fail!(n_number_1_dot_0e_); fail!(n_number_1_dot_0e); fail!(n_number_1_000); fail!(n_number_1eE2); fail!(n_number_2_dot_eplus3); fail!(n_number_2_dot_e_3); fail!(n_number_2_dot_e3); fail!(n_number_9_dot_eplus); fail!(n_number_expression); fail!(n_number_hex_1_digit); fail!(n_number_hex_2_digits); fail!(n_number_Inf); fail!(n_number_infinity); fail!(n_number_invalidplus_); fail!(n_number_invalid_negative_real); fail!(n_number_invalid_utf_8_in_bigger_int); fail!(n_number_invalid_utf_8_in_exponent); fail!(n_number_invalid_utf_8_in_int); fail!(n_number_minus_infinity); fail!(n_number_minus_sign_with_trailing_garbage); fail!(n_number_minus_space_1); fail!(n_number_NaN); fail!(n_number_neg_int_starting_with_zero); fail!(n_number_neg_real_without_int_part); fail!(n_number_neg_with_garbage_at_end); fail!(n_number_real_garbage_after_e); fail!(n_number_real_with_invalid_utf8_after_e); fail!(n_number_real_without_fractional_part); fail!(n_number_starting_with_dot); fail!(n_number_UplusFF11_fullwidth_digit_one); fail!(n_number_with_alpha); fail!(n_number_with_alpha_char); fail!(n_number_with_leading_zero); fail!(n_object_bad_value); fail!(n_object_bracket_key); fail!(n_object_comma_instead_of_colon); fail!(n_object_double_colon); fail!(n_object_emoji); fail!(n_object_garbage_at_end); fail!(n_object_key_with_single_quotes); fail!(n_object_lone_continuation_byte_in_key_and_trailing_comma); fail!(n_object_missing_colon); fail!(n_object_missing_key); fail!(n_object_missing_semicolon); fail!(n_object_missing_value); fail!(n_object_no_colon); fail!(n_object_non_string_key); fail!(n_object_non_string_key_but_huge_number_instead); fail!(n_object_repeated_null_null); fail!(n_object_several_trailing_commas); fail!(n_object_single_quote); fail!(n_object_trailing_comma); fail!(n_object_trailing_comment); fail!(n_object_trailing_comment_open); fail!(n_object_trailing_comment_slash_open); fail!(n_object_trailing_comment_slash_open_incomplete); fail!(n_object_two_commas_in_a_row); fail!(n_object_unquoted_key); fail!(n_object_unterminated_value); fail!(n_object_with_single_string); fail!(n_object_with_trailing_garbage); fail!(n_single_space); fail!(n_string_1_surrogate_then_escape); fail!(n_string_1_surrogate_then_escape_u); fail!(n_string_1_surrogate_then_escape_u1); fail!(n_string_1_surrogate_then_escape_u1x); fail!(n_string_accentuated_char_no_quotes); fail!(n_string_backslash_00); fail!(n_string_escape_x); fail!(n_string_escaped_backslash_bad); fail!(n_string_escaped_ctrl_char_tab); fail!(n_string_escaped_emoji); fail!(n_string_incomplete_escape); fail!(n_string_incomplete_escaped_character); fail!(n_string_incomplete_surrogate); fail!(n_string_incomplete_surrogate_escape_invalid); fail!(n_string_invalid_utf_8_in_escape); fail!(n_string_invalid_backslash_esc); fail!(n_string_invalid_unicode_escape); fail!(n_string_invalid_utf8_after_escape); fail!(n_string_leading_uescaped_thinspace); fail!(n_string_no_quotes_with_bad_escape); fail!(n_string_single_doublequote); fail!(n_string_single_quote); fail!(n_string_single_string_no_double_quotes); fail!(n_string_start_escape_unclosed); fail!(n_string_unescaped_ctrl_char); fail!(n_string_unescaped_newline); fail!(n_string_unescaped_tab); fail!(n_string_unicode_CapitalU); fail!(n_string_with_trailing_garbage); fail!(n_structure_100000_opening_arrays); fail!(n_structure_angle_bracket__dot_); fail!(n_structure_angle_bracket_null); fail!(n_structure_array_trailing_garbage); fail!(n_structure_array_with_extra_array_close); fail!(n_structure_array_with_unclosed_string); fail!(n_structure_ascii_unicode_identifier); fail!(n_structure_capitalized_True); fail!(n_structure_close_unopened_array); fail!(n_structure_comma_instead_of_closing_brace); fail!(n_structure_double_array); fail!(n_structure_end_array); fail!(n_structure_incomplete_UTF8_BOM); fail!(n_structure_lone_invalid_utf_8); fail!(n_structure_lone_open_bracket); fail!(n_structure_no_data); fail!(n_structure_null_byte_outside_string); fail!(n_structure_number_with_trailing_garbage); fail!(n_structure_object_followed_by_closing_object); fail!(n_structure_object_unclosed_no_value); fail!(n_structure_object_with_comment); fail!(n_structure_object_with_trailing_garbage); fail!(n_structure_open_array_apostrophe); fail!(n_structure_open_array_comma); fail!(n_structure_open_array_object); fail!(n_structure_open_array_open_object); fail!(n_structure_open_array_open_string); fail!(n_structure_open_array_string); fail!(n_structure_open_object); fail!(n_structure_open_object_close_array); fail!(n_structure_open_object_comma); fail!(n_structure_open_object_open_array); fail!(n_structure_open_object_open_string); fail!(n_structure_open_object_string_with_apostrophes); fail!(n_structure_open_open); fail!(n_structure_single_eacute); fail!(n_structure_single_star); fail!(n_structure_trailing_hash); fail!(n_structure_Uplus2060_word_joined); fail!(n_structure_uescaped_LF_before_string); fail!(n_structure_unclosed_array); fail!(n_structure_unclosed_array_partial_null); fail!(n_structure_unclosed_array_unfinished_false); fail!(n_structure_unclosed_array_unfinished_true); fail!(n_structure_unclosed_object); fail!(n_structure_unicode_identifier); fail!(n_structure_UTF8_BOM_no_data); fail!(n_structure_whitespace_formfeed); fail!(n_structure_whitespace_Uplus2060_word_joiner); pass!(y_array_arraysWithSpaces); pass!(y_array_empty_string); pass!(y_array_empty); pass!(y_array_ending_with_newline); pass!(y_array_false); pass!(y_array_heterogeneous); pass!(y_array_null); pass!(y_array_with_1_and_newline); pass!(y_array_with_leading_space); pass!(y_array_with_several_null); pass!(y_array_with_trailing_space); pass!(y_number); pass!(y_number_0eplus1); pass!(y_number_0e1); pass!(y_number_after_space); pass!(y_number_double_close_to_zero); pass!(y_number_int_with_exp); pass!(y_number_minus_zero); pass!(y_number_negative_int); pass!(y_number_negative_one); pass!(y_number_negative_zero); pass!(y_number_real_capital_e); pass!(y_number_real_capital_e_neg_exp); pass!(y_number_real_capital_e_pos_exp); pass!(y_number_real_exponent); pass!(y_number_real_fraction_exponent); pass!(y_number_real_neg_exp); pass!(y_number_real_pos_exponent); pass!(y_number_simple_int); pass!(y_number_simple_real); pass!(y_object); pass!(y_object_basic); pass!(y_object_duplicated_key); pass!(y_object_duplicated_key_and_value); pass!(y_object_empty); pass!(y_object_empty_key); pass!(y_object_escaped_null_in_key); pass!(y_object_extreme_numbers); pass!(y_object_long_strings); pass!(y_object_simple); pass!(y_object_string_unicode); pass!(y_object_with_newlines); pass!(y_string_1_2_3_bytes_UTF_8_sequences); pass!(y_string_accepted_surrogate_pair); pass!(y_string_accepted_surrogate_pairs); pass!(y_string_allowed_escapes); pass!(y_string_backslash_and_u_escaped_zero); pass!(y_string_backslash_doublequotes); pass!(y_string_comments); pass!(y_string_double_escape_a); pass!(y_string_double_escape_n); pass!(y_string_escaped_control_character); pass!(y_string_escaped_noncharacter); pass!(y_string_in_array); pass!(y_string_in_array_with_leading_space); pass!(y_string_last_surrogates_1_and_2); pass!(y_string_nbsp_uescaped); pass!(y_string_nonCharacterInUTF_8_Uplus10FFFF); pass!(y_string_nonCharacterInUTF_8_UplusFFFF); pass!(y_string_null_escape); pass!(y_string_one_byte_utf_8); pass!(y_string_pi); pass!(y_string_reservedCharacterInUTF_8_Uplus1BFFF); pass!(y_string_simple_ascii); pass!(y_string_space); pass!(y_string_surrogates_Uplus1D11E_MUSICAL_SYMBOL_G_CLEF); pass!(y_string_three_byte_utf_8); pass!(y_string_two_byte_utf_8); pass!(y_string_uplus2028_line_sep); pass!(y_string_uplus2029_par_sep); pass!(y_string_uEscape); pass!(y_string_uescaped_newline); pass!(y_string_unescaped_char_delete); pass!(y_string_unicode); pass!(y_string_unicode_2); pass!(y_string_unicode_escaped_double_quote); pass!(y_string_unicode_Uplus1FFFE_nonchar); pass!(y_string_unicode_Uplus10FFFE_nonchar); pass!(y_string_unicode_Uplus200B_ZERO_WIDTH_SPACE); pass!(y_string_unicode_Uplus2064_invisible_plus); pass!(y_string_unicode_UplusFDD0_nonchar); pass!(y_string_unicode_UplusFFFE_nonchar); pass!(y_string_unicodeEscapedBackslash); pass!(y_string_utf8); pass!(y_string_with_del_character); pass!(y_structure_lonely_false); pass!(y_structure_lonely_int); pass!(y_structure_lonely_negative_real); pass!(y_structure_lonely_null); pass!(y_structure_lonely_string); pass!(y_structure_lonely_true); pass!(y_structure_string_empty); pass!(y_structure_trailing_newline); pass!(y_structure_true_in_array); pass!(y_structure_whitespace_array);