1// RFC 8529 conformance tests. 2// 3// Tests are taken from https://github.com/nst/JSONTestSuite 4// Read also http://seriot.ch/parsing_json.php for a good overview. 5 6const std = @import("../std.zig"); 7const json = std.json; 8const testing = std.testing; 9 10fn testNonStreaming(s: []const u8) !void { 11 var p = json.Parser.init(testing.allocator, false); 12 defer p.deinit(); 13 14 var tree = try p.parse(s); 15 defer tree.deinit(); 16} 17 18fn ok(s: []const u8) !void { 19 try testing.expect(json.validate(s)); 20 21 try testNonStreaming(s); 22} 23 24fn err(s: []const u8) !void { 25 try testing.expect(!json.validate(s)); 26 27 try testing.expect(std.meta.isError(testNonStreaming(s))); 28} 29 30fn utf8Error(s: []const u8) !void { 31 try testing.expect(!json.validate(s)); 32 33 try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s)); 34} 35 36fn any(s: []const u8) !void { 37 _ = json.validate(s); 38 39 testNonStreaming(s) catch {}; 40} 41 42fn anyStreamingErrNonStreaming(s: []const u8) !void { 43 _ = json.validate(s); 44 45 try testing.expect(std.meta.isError(testNonStreaming(s))); 46} 47 48fn roundTrip(s: []const u8) !void { 49 try testing.expect(json.validate(s)); 50 51 var p = json.Parser.init(testing.allocator, false); 52 defer p.deinit(); 53 54 var tree = try p.parse(s); 55 defer tree.deinit(); 56 57 var buf: [256]u8 = undefined; 58 var fbs = std.io.fixedBufferStream(&buf); 59 try tree.root.jsonStringify(.{}, fbs.writer()); 60 61 try testing.expectEqualStrings(s, fbs.getWritten()); 62} 63 64//////////////////////////////////////////////////////////////////////////////////////////////////// 65// 66// Additional tests not part of test JSONTestSuite. 67 68test "y_trailing_comma_after_empty" { 69 try roundTrip( 70 \\{"1":[],"2":{},"3":"4"} 71 ); 72} 73 74test "n_object_closed_missing_value" { 75 try err( 76 \\{"a":} 77 ); 78} 79 80//////////////////////////////////////////////////////////////////////////////////////////////////// 81 82test "y_array_arraysWithSpaces" { 83 try ok( 84 \\[[] ] 85 ); 86} 87 88test "y_array_empty" { 89 try roundTrip( 90 \\[] 91 ); 92} 93 94test "y_array_empty-string" { 95 try roundTrip( 96 \\[""] 97 ); 98} 99 100test "y_array_ending_with_newline" { 101 try roundTrip( 102 \\["a"] 103 ); 104} 105 106test "y_array_false" { 107 try roundTrip( 108 \\[false] 109 ); 110} 111 112test "y_array_heterogeneous" { 113 try ok( 114 \\[null, 1, "1", {}] 115 ); 116} 117 118test "y_array_null" { 119 try roundTrip( 120 \\[null] 121 ); 122} 123 124test "y_array_with_1_and_newline" { 125 try ok( 126 \\[1 127 \\] 128 ); 129} 130 131test "y_array_with_leading_space" { 132 try ok( 133 \\ [1] 134 ); 135} 136 137test "y_array_with_several_null" { 138 try roundTrip( 139 \\[1,null,null,null,2] 140 ); 141} 142 143test "y_array_with_trailing_space" { 144 try ok("[2] "); 145} 146 147test "y_number_0e+1" { 148 try ok( 149 \\[0e+1] 150 ); 151} 152 153test "y_number_0e1" { 154 try ok( 155 \\[0e1] 156 ); 157} 158 159test "y_number_after_space" { 160 try ok( 161 \\[ 4] 162 ); 163} 164 165test "y_number_double_close_to_zero" { 166 try ok( 167 \\[-0.000000000000000000000000000000000000000000000000000000000000000000000000000001] 168 ); 169} 170 171test "y_number_int_with_exp" { 172 try ok( 173 \\[20e1] 174 ); 175} 176 177test "y_number" { 178 try ok( 179 \\[123e65] 180 ); 181} 182 183test "y_number_minus_zero" { 184 try ok( 185 \\[-0] 186 ); 187} 188 189test "y_number_negative_int" { 190 try roundTrip( 191 \\[-123] 192 ); 193} 194 195test "y_number_negative_one" { 196 try roundTrip( 197 \\[-1] 198 ); 199} 200 201test "y_number_negative_zero" { 202 try ok( 203 \\[-0] 204 ); 205} 206 207test "y_number_real_capital_e" { 208 try ok( 209 \\[1E22] 210 ); 211} 212 213test "y_number_real_capital_e_neg_exp" { 214 try ok( 215 \\[1E-2] 216 ); 217} 218 219test "y_number_real_capital_e_pos_exp" { 220 try ok( 221 \\[1E+2] 222 ); 223} 224 225test "y_number_real_exponent" { 226 try ok( 227 \\[123e45] 228 ); 229} 230 231test "y_number_real_fraction_exponent" { 232 try ok( 233 \\[123.456e78] 234 ); 235} 236 237test "y_number_real_neg_exp" { 238 try ok( 239 \\[1e-2] 240 ); 241} 242 243test "y_number_real_pos_exponent" { 244 try ok( 245 \\[1e+2] 246 ); 247} 248 249test "y_number_simple_int" { 250 try roundTrip( 251 \\[123] 252 ); 253} 254 255test "y_number_simple_real" { 256 try ok( 257 \\[123.456789] 258 ); 259} 260 261test "y_object_basic" { 262 try roundTrip( 263 \\{"asd":"sdf"} 264 ); 265} 266 267test "y_object_duplicated_key_and_value" { 268 try ok( 269 \\{"a":"b","a":"b"} 270 ); 271} 272 273test "y_object_duplicated_key" { 274 try ok( 275 \\{"a":"b","a":"c"} 276 ); 277} 278 279test "y_object_empty" { 280 try roundTrip( 281 \\{} 282 ); 283} 284 285test "y_object_empty_key" { 286 try roundTrip( 287 \\{"":0} 288 ); 289} 290 291test "y_object_escaped_null_in_key" { 292 try ok( 293 \\{"foo\u0000bar": 42} 294 ); 295} 296 297test "y_object_extreme_numbers" { 298 try ok( 299 \\{ "min": -1.0e+28, "max": 1.0e+28 } 300 ); 301} 302 303test "y_object" { 304 try ok( 305 \\{"asd":"sdf", "dfg":"fgh"} 306 ); 307} 308 309test "y_object_long_strings" { 310 try ok( 311 \\{"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} 312 ); 313} 314 315test "y_object_simple" { 316 try roundTrip( 317 \\{"a":[]} 318 ); 319} 320 321test "y_object_string_unicode" { 322 try ok( 323 \\{"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" } 324 ); 325} 326 327test "y_object_with_newlines" { 328 try ok( 329 \\{ 330 \\"a": "b" 331 \\} 332 ); 333} 334 335test "y_string_1_2_3_bytes_UTF-8_sequences" { 336 try ok( 337 \\["\u0060\u012a\u12AB"] 338 ); 339} 340 341test "y_string_accepted_surrogate_pair" { 342 try ok( 343 \\["\uD801\udc37"] 344 ); 345} 346 347test "y_string_accepted_surrogate_pairs" { 348 try ok( 349 \\["\ud83d\ude39\ud83d\udc8d"] 350 ); 351} 352 353test "y_string_allowed_escapes" { 354 try ok( 355 \\["\"\\\/\b\f\n\r\t"] 356 ); 357} 358 359test "y_string_backslash_and_u_escaped_zero" { 360 try ok( 361 \\["\\u0000"] 362 ); 363} 364 365test "y_string_backslash_doublequotes" { 366 try roundTrip( 367 \\["\""] 368 ); 369} 370 371test "y_string_comments" { 372 try ok( 373 \\["a/*b*/c/*d//e"] 374 ); 375} 376 377test "y_string_double_escape_a" { 378 try ok( 379 \\["\\a"] 380 ); 381} 382 383test "y_string_double_escape_n" { 384 try roundTrip( 385 \\["\\n"] 386 ); 387} 388 389test "y_string_escaped_control_character" { 390 try ok( 391 \\["\u0012"] 392 ); 393} 394 395test "y_string_escaped_noncharacter" { 396 try ok( 397 \\["\uFFFF"] 398 ); 399} 400 401test "y_string_in_array" { 402 try ok( 403 \\["asd"] 404 ); 405} 406 407test "y_string_in_array_with_leading_space" { 408 try ok( 409 \\[ "asd"] 410 ); 411} 412 413test "y_string_last_surrogates_1_and_2" { 414 try ok( 415 \\["\uDBFF\uDFFF"] 416 ); 417} 418 419test "y_string_nbsp_uescaped" { 420 try ok( 421 \\["new\u00A0line"] 422 ); 423} 424 425test "y_string_nonCharacterInUTF-8_U+10FFFF" { 426 try ok( 427 \\[""] 428 ); 429} 430 431test "y_string_nonCharacterInUTF-8_U+FFFF" { 432 try ok( 433 \\[""] 434 ); 435} 436 437test "y_string_null_escape" { 438 try ok( 439 \\["\u0000"] 440 ); 441} 442 443test "y_string_one-byte-utf-8" { 444 try ok( 445 \\["\u002c"] 446 ); 447} 448 449test "y_string_pi" { 450 try ok( 451 \\["π"] 452 ); 453} 454 455test "y_string_reservedCharacterInUTF-8_U+1BFFF" { 456 try ok( 457 \\[""] 458 ); 459} 460 461test "y_string_simple_ascii" { 462 try ok( 463 \\["asd "] 464 ); 465} 466 467test "y_string_space" { 468 try roundTrip( 469 \\" " 470 ); 471} 472 473test "y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF" { 474 try ok( 475 \\["\uD834\uDd1e"] 476 ); 477} 478 479test "y_string_three-byte-utf-8" { 480 try ok( 481 \\["\u0821"] 482 ); 483} 484 485test "y_string_two-byte-utf-8" { 486 try ok( 487 \\["\u0123"] 488 ); 489} 490 491test "y_string_u+2028_line_sep" { 492 try ok("[\"\xe2\x80\xa8\"]"); 493} 494 495test "y_string_u+2029_par_sep" { 496 try ok("[\"\xe2\x80\xa9\"]"); 497} 498 499test "y_string_uescaped_newline" { 500 try ok( 501 \\["new\u000Aline"] 502 ); 503} 504 505test "y_string_uEscape" { 506 try ok( 507 \\["\u0061\u30af\u30EA\u30b9"] 508 ); 509} 510 511test "y_string_unescaped_char_delete" { 512 try ok("[\"\x7f\"]"); 513} 514 515test "y_string_unicode_2" { 516 try ok( 517 \\["⍂㈴⍂"] 518 ); 519} 520 521test "y_string_unicodeEscapedBackslash" { 522 try ok( 523 \\["\u005C"] 524 ); 525} 526 527test "y_string_unicode_escaped_double_quote" { 528 try ok( 529 \\["\u0022"] 530 ); 531} 532 533test "y_string_unicode" { 534 try ok( 535 \\["\uA66D"] 536 ); 537} 538 539test "y_string_unicode_U+10FFFE_nonchar" { 540 try ok( 541 \\["\uDBFF\uDFFE"] 542 ); 543} 544 545test "y_string_unicode_U+1FFFE_nonchar" { 546 try ok( 547 \\["\uD83F\uDFFE"] 548 ); 549} 550 551test "y_string_unicode_U+200B_ZERO_WIDTH_SPACE" { 552 try ok( 553 \\["\u200B"] 554 ); 555} 556 557test "y_string_unicode_U+2064_invisible_plus" { 558 try ok( 559 \\["\u2064"] 560 ); 561} 562 563test "y_string_unicode_U+FDD0_nonchar" { 564 try ok( 565 \\["\uFDD0"] 566 ); 567} 568 569test "y_string_unicode_U+FFFE_nonchar" { 570 try ok( 571 \\["\uFFFE"] 572 ); 573} 574 575test "y_string_utf8" { 576 try ok( 577 \\["€"] 578 ); 579} 580 581test "y_string_with_del_character" { 582 try ok("[\"a\x7fa\"]"); 583} 584 585test "y_structure_lonely_false" { 586 try roundTrip( 587 \\false 588 ); 589} 590 591test "y_structure_lonely_int" { 592 try roundTrip( 593 \\42 594 ); 595} 596 597test "y_structure_lonely_negative_real" { 598 try ok( 599 \\-0.1 600 ); 601} 602 603test "y_structure_lonely_null" { 604 try roundTrip( 605 \\null 606 ); 607} 608 609test "y_structure_lonely_string" { 610 try roundTrip( 611 \\"asd" 612 ); 613} 614 615test "y_structure_lonely_true" { 616 try roundTrip( 617 \\true 618 ); 619} 620 621test "y_structure_string_empty" { 622 try roundTrip( 623 \\"" 624 ); 625} 626 627test "y_structure_trailing_newline" { 628 try roundTrip( 629 \\["a"] 630 ); 631} 632 633test "y_structure_true_in_array" { 634 try roundTrip( 635 \\[true] 636 ); 637} 638 639test "y_structure_whitespace_array" { 640 try ok(" [] "); 641} 642 643//////////////////////////////////////////////////////////////////////////////////////////////////// 644 645test "n_array_1_true_without_comma" { 646 try err( 647 \\[1 true] 648 ); 649} 650 651test "n_array_a_invalid_utf8" { 652 try err( 653 \\[aå] 654 ); 655} 656 657test "n_array_colon_instead_of_comma" { 658 try err( 659 \\["": 1] 660 ); 661} 662 663test "n_array_comma_after_close" { 664 try err( 665 \\[""], 666 ); 667} 668 669test "n_array_comma_and_number" { 670 try err( 671 \\[,1] 672 ); 673} 674 675test "n_array_double_comma" { 676 try err( 677 \\[1,,2] 678 ); 679} 680 681test "n_array_double_extra_comma" { 682 try err( 683 \\["x",,] 684 ); 685} 686 687test "n_array_extra_close" { 688 try err( 689 \\["x"]] 690 ); 691} 692 693test "n_array_extra_comma" { 694 try err( 695 \\["",] 696 ); 697} 698 699test "n_array_incomplete_invalid_value" { 700 try err( 701 \\[x 702 ); 703} 704 705test "n_array_incomplete" { 706 try err( 707 \\["x" 708 ); 709} 710 711test "n_array_inner_array_no_comma" { 712 try err( 713 \\[3[4]] 714 ); 715} 716 717test "n_array_invalid_utf8" { 718 try err( 719 \\[ÿ] 720 ); 721} 722 723test "n_array_items_separated_by_semicolon" { 724 try err( 725 \\[1:2] 726 ); 727} 728 729test "n_array_just_comma" { 730 try err( 731 \\[,] 732 ); 733} 734 735test "n_array_just_minus" { 736 try err( 737 \\[-] 738 ); 739} 740 741test "n_array_missing_value" { 742 try err( 743 \\[ , ""] 744 ); 745} 746 747test "n_array_newlines_unclosed" { 748 try err( 749 \\["a", 750 \\4 751 \\,1, 752 ); 753} 754 755test "n_array_number_and_comma" { 756 try err( 757 \\[1,] 758 ); 759} 760 761test "n_array_number_and_several_commas" { 762 try err( 763 \\[1,,] 764 ); 765} 766 767test "n_array_spaces_vertical_tab_formfeed" { 768 try err("[\"\x0aa\"\\f]"); 769} 770 771test "n_array_star_inside" { 772 try err( 773 \\[*] 774 ); 775} 776 777test "n_array_unclosed" { 778 try err( 779 \\["" 780 ); 781} 782 783test "n_array_unclosed_trailing_comma" { 784 try err( 785 \\[1, 786 ); 787} 788 789test "n_array_unclosed_with_new_lines" { 790 try err( 791 \\[1, 792 \\1 793 \\,1 794 ); 795} 796 797test "n_array_unclosed_with_object_inside" { 798 try err( 799 \\[{} 800 ); 801} 802 803test "n_incomplete_false" { 804 try err( 805 \\[fals] 806 ); 807} 808 809test "n_incomplete_null" { 810 try err( 811 \\[nul] 812 ); 813} 814 815test "n_incomplete_true" { 816 try err( 817 \\[tru] 818 ); 819} 820 821test "n_multidigit_number_then_00" { 822 try err("123\x00"); 823} 824 825test "n_number_0.1.2" { 826 try err( 827 \\[0.1.2] 828 ); 829} 830 831test "n_number_-01" { 832 try err( 833 \\[-01] 834 ); 835} 836 837test "n_number_0.3e" { 838 try err( 839 \\[0.3e] 840 ); 841} 842 843test "n_number_0.3e+" { 844 try err( 845 \\[0.3e+] 846 ); 847} 848 849test "n_number_0_capital_E" { 850 try err( 851 \\[0E] 852 ); 853} 854 855test "n_number_0_capital_E+" { 856 try err( 857 \\[0E+] 858 ); 859} 860 861test "n_number_0.e1" { 862 try err( 863 \\[0.e1] 864 ); 865} 866 867test "n_number_0e" { 868 try err( 869 \\[0e] 870 ); 871} 872 873test "n_number_0e+" { 874 try err( 875 \\[0e+] 876 ); 877} 878 879test "n_number_1_000" { 880 try err( 881 \\[1 000.0] 882 ); 883} 884 885test "n_number_1.0e-" { 886 try err( 887 \\[1.0e-] 888 ); 889} 890 891test "n_number_1.0e" { 892 try err( 893 \\[1.0e] 894 ); 895} 896 897test "n_number_1.0e+" { 898 try err( 899 \\[1.0e+] 900 ); 901} 902 903test "n_number_-1.0." { 904 try err( 905 \\[-1.0.] 906 ); 907} 908 909test "n_number_1eE2" { 910 try err( 911 \\[1eE2] 912 ); 913} 914 915test "n_number_.-1" { 916 try err( 917 \\[.-1] 918 ); 919} 920 921test "n_number_+1" { 922 try err( 923 \\[+1] 924 ); 925} 926 927test "n_number_.2e-3" { 928 try err( 929 \\[.2e-3] 930 ); 931} 932 933test "n_number_2.e-3" { 934 try err( 935 \\[2.e-3] 936 ); 937} 938 939test "n_number_2.e+3" { 940 try err( 941 \\[2.e+3] 942 ); 943} 944 945test "n_number_2.e3" { 946 try err( 947 \\[2.e3] 948 ); 949} 950 951test "n_number_-2." { 952 try err( 953 \\[-2.] 954 ); 955} 956 957test "n_number_9.e+" { 958 try err( 959 \\[9.e+] 960 ); 961} 962 963test "n_number_expression" { 964 try err( 965 \\[1+2] 966 ); 967} 968 969test "n_number_hex_1_digit" { 970 try err( 971 \\[0x1] 972 ); 973} 974 975test "n_number_hex_2_digits" { 976 try err( 977 \\[0x42] 978 ); 979} 980 981test "n_number_infinity" { 982 try err( 983 \\[Infinity] 984 ); 985} 986 987test "n_number_+Inf" { 988 try err( 989 \\[+Inf] 990 ); 991} 992 993test "n_number_Inf" { 994 try err( 995 \\[Inf] 996 ); 997} 998 999test "n_number_invalid+-" { 1000 try err( 1001 \\[0e+-1] 1002 ); 1003} 1004 1005test "n_number_invalid-negative-real" { 1006 try err( 1007 \\[-123.123foo] 1008 ); 1009} 1010 1011test "n_number_invalid-utf-8-in-bigger-int" { 1012 try err( 1013 \\[123å] 1014 ); 1015} 1016 1017test "n_number_invalid-utf-8-in-exponent" { 1018 try err( 1019 \\[1e1å] 1020 ); 1021} 1022 1023test "n_number_invalid-utf-8-in-int" { 1024 try err( 1025 \\[0å] 1026 ); 1027} 1028 1029test "n_number_++" { 1030 try err( 1031 \\[++1234] 1032 ); 1033} 1034 1035test "n_number_minus_infinity" { 1036 try err( 1037 \\[-Infinity] 1038 ); 1039} 1040 1041test "n_number_minus_sign_with_trailing_garbage" { 1042 try err( 1043 \\[-foo] 1044 ); 1045} 1046 1047test "n_number_minus_space_1" { 1048 try err( 1049 \\[- 1] 1050 ); 1051} 1052 1053test "n_number_-NaN" { 1054 try err( 1055 \\[-NaN] 1056 ); 1057} 1058 1059test "n_number_NaN" { 1060 try err( 1061 \\[NaN] 1062 ); 1063} 1064 1065test "n_number_neg_int_starting_with_zero" { 1066 try err( 1067 \\[-012] 1068 ); 1069} 1070 1071test "n_number_neg_real_without_int_part" { 1072 try err( 1073 \\[-.123] 1074 ); 1075} 1076 1077test "n_number_neg_with_garbage_at_end" { 1078 try err( 1079 \\[-1x] 1080 ); 1081} 1082 1083test "n_number_real_garbage_after_e" { 1084 try err( 1085 \\[1ea] 1086 ); 1087} 1088 1089test "n_number_real_with_invalid_utf8_after_e" { 1090 try err( 1091 \\[1eå] 1092 ); 1093} 1094 1095test "n_number_real_without_fractional_part" { 1096 try err( 1097 \\[1.] 1098 ); 1099} 1100 1101test "n_number_starting_with_dot" { 1102 try err( 1103 \\[.123] 1104 ); 1105} 1106 1107test "n_number_U+FF11_fullwidth_digit_one" { 1108 try err( 1109 \\[ï¼] 1110 ); 1111} 1112 1113test "n_number_with_alpha_char" { 1114 try err( 1115 \\[1.8011670033376514H-308] 1116 ); 1117} 1118 1119test "n_number_with_alpha" { 1120 try err( 1121 \\[1.2a-3] 1122 ); 1123} 1124 1125test "n_number_with_leading_zero" { 1126 try err( 1127 \\[012] 1128 ); 1129} 1130 1131test "n_object_bad_value" { 1132 try err( 1133 \\["x", truth] 1134 ); 1135} 1136 1137test "n_object_bracket_key" { 1138 try err( 1139 \\{[: "x"} 1140 ); 1141} 1142 1143test "n_object_comma_instead_of_colon" { 1144 try err( 1145 \\{"x", null} 1146 ); 1147} 1148 1149test "n_object_double_colon" { 1150 try err( 1151 \\{"x"::"b"} 1152 ); 1153} 1154 1155test "n_object_emoji" { 1156 try err( 1157 \\{ð¨ð} 1158 ); 1159} 1160 1161test "n_object_garbage_at_end" { 1162 try err( 1163 \\{"a":"a" 123} 1164 ); 1165} 1166 1167test "n_object_key_with_single_quotes" { 1168 try err( 1169 \\{key: 'value'} 1170 ); 1171} 1172 1173test "n_object_lone_continuation_byte_in_key_and_trailing_comma" { 1174 try err( 1175 \\{"¹":"0",} 1176 ); 1177} 1178 1179test "n_object_missing_colon" { 1180 try err( 1181 \\{"a" b} 1182 ); 1183} 1184 1185test "n_object_missing_key" { 1186 try err( 1187 \\{:"b"} 1188 ); 1189} 1190 1191test "n_object_missing_semicolon" { 1192 try err( 1193 \\{"a" "b"} 1194 ); 1195} 1196 1197test "n_object_missing_value" { 1198 try err( 1199 \\{"a": 1200 ); 1201} 1202 1203test "n_object_no-colon" { 1204 try err( 1205 \\{"a" 1206 ); 1207} 1208 1209test "n_object_non_string_key_but_huge_number_instead" { 1210 try err( 1211 \\{9999E9999:1} 1212 ); 1213} 1214 1215test "n_object_non_string_key" { 1216 try err( 1217 \\{1:1} 1218 ); 1219} 1220 1221test "n_object_repeated_null_null" { 1222 try err( 1223 \\{null:null,null:null} 1224 ); 1225} 1226 1227test "n_object_several_trailing_commas" { 1228 try err( 1229 \\{"id":0,,,,,} 1230 ); 1231} 1232 1233test "n_object_single_quote" { 1234 try err( 1235 \\{'a':0} 1236 ); 1237} 1238 1239test "n_object_trailing_comma" { 1240 try err( 1241 \\{"id":0,} 1242 ); 1243} 1244 1245test "n_object_trailing_comment" { 1246 try err( 1247 \\{"a":"b"}/**/ 1248 ); 1249} 1250 1251test "n_object_trailing_comment_open" { 1252 try err( 1253 \\{"a":"b"}/**// 1254 ); 1255} 1256 1257test "n_object_trailing_comment_slash_open_incomplete" { 1258 try err( 1259 \\{"a":"b"}/ 1260 ); 1261} 1262 1263test "n_object_trailing_comment_slash_open" { 1264 try err( 1265 \\{"a":"b"}// 1266 ); 1267} 1268 1269test "n_object_two_commas_in_a_row" { 1270 try err( 1271 \\{"a":"b",,"c":"d"} 1272 ); 1273} 1274 1275test "n_object_unquoted_key" { 1276 try err( 1277 \\{a: "b"} 1278 ); 1279} 1280 1281test "n_object_unterminated-value" { 1282 try err( 1283 \\{"a":"a 1284 ); 1285} 1286 1287test "n_object_with_single_string" { 1288 try err( 1289 \\{ "foo" : "bar", "a" } 1290 ); 1291} 1292 1293test "n_object_with_trailing_garbage" { 1294 try err( 1295 \\{"a":"b"}# 1296 ); 1297} 1298 1299test "n_single_space" { 1300 try err(" "); 1301} 1302 1303test "n_string_1_surrogate_then_escape" { 1304 try err( 1305 \\["\uD800\"] 1306 ); 1307} 1308 1309test "n_string_1_surrogate_then_escape_u1" { 1310 try err( 1311 \\["\uD800\u1"] 1312 ); 1313} 1314 1315test "n_string_1_surrogate_then_escape_u1x" { 1316 try err( 1317 \\["\uD800\u1x"] 1318 ); 1319} 1320 1321test "n_string_1_surrogate_then_escape_u" { 1322 try err( 1323 \\["\uD800\u"] 1324 ); 1325} 1326 1327test "n_string_accentuated_char_no_quotes" { 1328 try err( 1329 \\[é] 1330 ); 1331} 1332 1333test "n_string_backslash_00" { 1334 try err("[\"\x00\"]"); 1335} 1336 1337test "n_string_escaped_backslash_bad" { 1338 try err( 1339 \\["\\\"] 1340 ); 1341} 1342 1343test "n_string_escaped_ctrl_char_tab" { 1344 try err("\x5b\x22\x5c\x09\x22\x5d"); 1345} 1346 1347test "n_string_escaped_emoji" { 1348 try err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]"); 1349} 1350 1351test "n_string_escape_x" { 1352 try err( 1353 \\["\x00"] 1354 ); 1355} 1356 1357test "n_string_incomplete_escaped_character" { 1358 try err( 1359 \\["\u00A"] 1360 ); 1361} 1362 1363test "n_string_incomplete_escape" { 1364 try err( 1365 \\["\"] 1366 ); 1367} 1368 1369test "n_string_incomplete_surrogate_escape_invalid" { 1370 try err( 1371 \\["\uD800\uD800\x"] 1372 ); 1373} 1374 1375test "n_string_incomplete_surrogate" { 1376 try err( 1377 \\["\uD834\uDd"] 1378 ); 1379} 1380 1381test "n_string_invalid_backslash_esc" { 1382 try err( 1383 \\["\a"] 1384 ); 1385} 1386 1387test "n_string_invalid_unicode_escape" { 1388 try err( 1389 \\["\uqqqq"] 1390 ); 1391} 1392 1393test "n_string_invalid_utf8_after_escape" { 1394 try err("[\"\\\x75\xc3\xa5\"]"); 1395} 1396 1397test "n_string_invalid-utf-8-in-escape" { 1398 try err( 1399 \\["\uå"] 1400 ); 1401} 1402 1403test "n_string_leading_uescaped_thinspace" { 1404 try err( 1405 \\[\u0020"asd"] 1406 ); 1407} 1408 1409test "n_string_no_quotes_with_bad_escape" { 1410 try err( 1411 \\[\n] 1412 ); 1413} 1414 1415test "n_string_single_doublequote" { 1416 try err( 1417 \\" 1418 ); 1419} 1420 1421test "n_string_single_quote" { 1422 try err( 1423 \\['single quote'] 1424 ); 1425} 1426 1427test "n_string_single_string_no_double_quotes" { 1428 try err( 1429 \\abc 1430 ); 1431} 1432 1433test "n_string_start_escape_unclosed" { 1434 try err( 1435 \\["\ 1436 ); 1437} 1438 1439test "n_string_unescaped_crtl_char" { 1440 try err("[\"a\x00a\"]"); 1441} 1442 1443test "n_string_unescaped_newline" { 1444 try err( 1445 \\["new 1446 \\line"] 1447 ); 1448} 1449 1450test "n_string_unescaped_tab" { 1451 try err("[\"\t\"]"); 1452} 1453 1454test "n_string_unicode_CapitalU" { 1455 try err( 1456 \\"\UA66D" 1457 ); 1458} 1459 1460test "n_string_with_trailing_garbage" { 1461 try err( 1462 \\""x 1463 ); 1464} 1465 1466test "n_structure_100000_opening_arrays" { 1467 try err("[" ** 100000); 1468} 1469 1470test "n_structure_angle_bracket_." { 1471 try err( 1472 \\<.> 1473 ); 1474} 1475 1476test "n_structure_angle_bracket_null" { 1477 try err( 1478 \\[<null>] 1479 ); 1480} 1481 1482test "n_structure_array_trailing_garbage" { 1483 try err( 1484 \\[1]x 1485 ); 1486} 1487 1488test "n_structure_array_with_extra_array_close" { 1489 try err( 1490 \\[1]] 1491 ); 1492} 1493 1494test "n_structure_array_with_unclosed_string" { 1495 try err( 1496 \\["asd] 1497 ); 1498} 1499 1500test "n_structure_ascii-unicode-identifier" { 1501 try err( 1502 \\aÃ¥ 1503 ); 1504} 1505 1506test "n_structure_capitalized_True" { 1507 try err( 1508 \\[True] 1509 ); 1510} 1511 1512test "n_structure_close_unopened_array" { 1513 try err( 1514 \\1] 1515 ); 1516} 1517 1518test "n_structure_comma_instead_of_closing_brace" { 1519 try err( 1520 \\{"x": true, 1521 ); 1522} 1523 1524test "n_structure_double_array" { 1525 try err( 1526 \\[][] 1527 ); 1528} 1529 1530test "n_structure_end_array" { 1531 try err( 1532 \\] 1533 ); 1534} 1535 1536test "n_structure_incomplete_UTF8_BOM" { 1537 try err( 1538 \\ï»{} 1539 ); 1540} 1541 1542test "n_structure_lone-invalid-utf-8" { 1543 try err( 1544 \\å 1545 ); 1546} 1547 1548test "n_structure_lone-open-bracket" { 1549 try err( 1550 \\[ 1551 ); 1552} 1553 1554test "n_structure_no_data" { 1555 try err( 1556 \\ 1557 ); 1558} 1559 1560test "n_structure_null-byte-outside-string" { 1561 try err("[\x00]"); 1562} 1563 1564test "n_structure_number_with_trailing_garbage" { 1565 try err( 1566 \\2@ 1567 ); 1568} 1569 1570test "n_structure_object_followed_by_closing_object" { 1571 try err( 1572 \\{}} 1573 ); 1574} 1575 1576test "n_structure_object_unclosed_no_value" { 1577 try err( 1578 \\{"": 1579 ); 1580} 1581 1582test "n_structure_object_with_comment" { 1583 try err( 1584 \\{"a":/*comment*/"b"} 1585 ); 1586} 1587 1588test "n_structure_object_with_trailing_garbage" { 1589 try err( 1590 \\{"a": true} "x" 1591 ); 1592} 1593 1594test "n_structure_open_array_apostrophe" { 1595 try err( 1596 \\[' 1597 ); 1598} 1599 1600test "n_structure_open_array_comma" { 1601 try err( 1602 \\[, 1603 ); 1604} 1605 1606test "n_structure_open_array_object" { 1607 try err("[{\"\":" ** 50000); 1608} 1609 1610test "n_structure_open_array_open_object" { 1611 try err( 1612 \\[{ 1613 ); 1614} 1615 1616test "n_structure_open_array_open_string" { 1617 try err( 1618 \\["a 1619 ); 1620} 1621 1622test "n_structure_open_array_string" { 1623 try err( 1624 \\["a" 1625 ); 1626} 1627 1628test "n_structure_open_object_close_array" { 1629 try err( 1630 \\{] 1631 ); 1632} 1633 1634test "n_structure_open_object_comma" { 1635 try err( 1636 \\{, 1637 ); 1638} 1639 1640test "n_structure_open_object" { 1641 try err( 1642 \\{ 1643 ); 1644} 1645 1646test "n_structure_open_object_open_array" { 1647 try err( 1648 \\{[ 1649 ); 1650} 1651 1652test "n_structure_open_object_open_string" { 1653 try err( 1654 \\{"a 1655 ); 1656} 1657 1658test "n_structure_open_object_string_with_apostrophes" { 1659 try err( 1660 \\{'a' 1661 ); 1662} 1663 1664test "n_structure_open_open" { 1665 try err( 1666 \\["\{["\{["\{["\{ 1667 ); 1668} 1669 1670test "n_structure_single_eacute" { 1671 try err( 1672 \\é 1673 ); 1674} 1675 1676test "n_structure_single_star" { 1677 try err( 1678 \\* 1679 ); 1680} 1681 1682test "n_structure_trailing_#" { 1683 try err( 1684 \\{"a":"b"}#{} 1685 ); 1686} 1687 1688test "n_structure_U+2060_word_joined" { 1689 try err( 1690 \\[â ] 1691 ); 1692} 1693 1694test "n_structure_uescaped_LF_before_string" { 1695 try err( 1696 \\[\u000A""] 1697 ); 1698} 1699 1700test "n_structure_unclosed_array" { 1701 try err( 1702 \\[1 1703 ); 1704} 1705 1706test "n_structure_unclosed_array_partial_null" { 1707 try err( 1708 \\[ false, nul 1709 ); 1710} 1711 1712test "n_structure_unclosed_array_unfinished_false" { 1713 try err( 1714 \\[ true, fals 1715 ); 1716} 1717 1718test "n_structure_unclosed_array_unfinished_true" { 1719 try err( 1720 \\[ false, tru 1721 ); 1722} 1723 1724test "n_structure_unclosed_object" { 1725 try err( 1726 \\{"asd":"asd" 1727 ); 1728} 1729 1730test "n_structure_unicode-identifier" { 1731 try err( 1732 \\Ã¥ 1733 ); 1734} 1735 1736test "n_structure_UTF8_BOM_no_data" { 1737 try err( 1738 \\ 1739 ); 1740} 1741 1742test "n_structure_whitespace_formfeed" { 1743 try err("[\x0c]"); 1744} 1745 1746test "n_structure_whitespace_U+2060_word_joiner" { 1747 try err( 1748 \\[â ] 1749 ); 1750} 1751 1752//////////////////////////////////////////////////////////////////////////////////////////////////// 1753 1754test "i_number_double_huge_neg_exp" { 1755 try any( 1756 \\[123.456e-789] 1757 ); 1758} 1759 1760test "i_number_huge_exp" { 1761 try any( 1762 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] 1763 ); 1764} 1765 1766test "i_number_neg_int_huge_exp" { 1767 try any( 1768 \\[-1e+9999] 1769 ); 1770} 1771 1772test "i_number_pos_double_huge_exp" { 1773 try any( 1774 \\[1.5e+9999] 1775 ); 1776} 1777 1778test "i_number_real_neg_overflow" { 1779 try any( 1780 \\[-123123e100000] 1781 ); 1782} 1783 1784test "i_number_real_pos_overflow" { 1785 try any( 1786 \\[123123e100000] 1787 ); 1788} 1789 1790test "i_number_real_underflow" { 1791 try any( 1792 \\[123e-10000000] 1793 ); 1794} 1795 1796test "i_number_too_big_neg_int" { 1797 try any( 1798 \\[-123123123123123123123123123123] 1799 ); 1800} 1801 1802test "i_number_too_big_pos_int" { 1803 try any( 1804 \\[100000000000000000000] 1805 ); 1806} 1807 1808test "i_number_very_big_negative_int" { 1809 try any( 1810 \\[-237462374673276894279832749832423479823246327846] 1811 ); 1812} 1813 1814test "i_object_key_lone_2nd_surrogate" { 1815 try anyStreamingErrNonStreaming( 1816 \\{"\uDFAA":0} 1817 ); 1818} 1819 1820test "i_string_1st_surrogate_but_2nd_missing" { 1821 try anyStreamingErrNonStreaming( 1822 \\["\uDADA"] 1823 ); 1824} 1825 1826test "i_string_1st_valid_surrogate_2nd_invalid" { 1827 try anyStreamingErrNonStreaming( 1828 \\["\uD888\u1234"] 1829 ); 1830} 1831 1832test "i_string_incomplete_surrogate_and_escape_valid" { 1833 try anyStreamingErrNonStreaming( 1834 \\["\uD800\n"] 1835 ); 1836} 1837 1838test "i_string_incomplete_surrogate_pair" { 1839 try anyStreamingErrNonStreaming( 1840 \\["\uDd1ea"] 1841 ); 1842} 1843 1844test "i_string_incomplete_surrogates_escape_valid" { 1845 try anyStreamingErrNonStreaming( 1846 \\["\uD800\uD800\n"] 1847 ); 1848} 1849 1850test "i_string_invalid_lonely_surrogate" { 1851 try anyStreamingErrNonStreaming( 1852 \\["\ud800"] 1853 ); 1854} 1855 1856test "i_string_invalid_surrogate" { 1857 try anyStreamingErrNonStreaming( 1858 \\["\ud800abc"] 1859 ); 1860} 1861 1862test "i_string_invalid_utf-8" { 1863 try any( 1864 \\["ÿ"] 1865 ); 1866} 1867 1868test "i_string_inverted_surrogates_U+1D11E" { 1869 try anyStreamingErrNonStreaming( 1870 \\["\uDd1e\uD834"] 1871 ); 1872} 1873 1874test "i_string_iso_latin_1" { 1875 try any( 1876 \\["é"] 1877 ); 1878} 1879 1880test "i_string_lone_second_surrogate" { 1881 try anyStreamingErrNonStreaming( 1882 \\["\uDFAA"] 1883 ); 1884} 1885 1886test "i_string_lone_utf8_continuation_byte" { 1887 try any( 1888 \\[""] 1889 ); 1890} 1891 1892test "i_string_not_in_unicode_range" { 1893 try any( 1894 \\["ô¿¿¿"] 1895 ); 1896} 1897 1898test "i_string_overlong_sequence_2_bytes" { 1899 try any( 1900 \\["À¯"] 1901 ); 1902} 1903 1904test "i_string_overlong_sequence_6_bytes" { 1905 try any( 1906 \\["ü¿¿¿¿"] 1907 ); 1908} 1909 1910test "i_string_overlong_sequence_6_bytes_null" { 1911 try any( 1912 \\["ü"] 1913 ); 1914} 1915 1916test "i_string_truncated-utf-8" { 1917 try any( 1918 \\["àÿ"] 1919 ); 1920} 1921 1922test "i_string_utf16BE_no_BOM" { 1923 try any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d"); 1924} 1925 1926test "i_string_utf16LE_no_BOM" { 1927 try any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00"); 1928} 1929 1930test "i_string_UTF-16LE_with_BOM" { 1931 try any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00"); 1932} 1933 1934test "i_string_UTF-8_invalid_sequence" { 1935 try any( 1936 \\["æ¥Ñú"] 1937 ); 1938} 1939 1940test "i_string_UTF8_surrogate_U+D800" { 1941 try any( 1942 \\["í "] 1943 ); 1944} 1945 1946test "i_structure_500_nested_arrays" { 1947 try any(("[" ** 500) ++ ("]" ** 500)); 1948} 1949 1950test "i_structure_UTF-8_BOM_empty_object" { 1951 try any( 1952 \\{} 1953 ); 1954} 1955 1956test "truncated UTF-8 sequence" { 1957 try utf8Error("\"\xc2\""); 1958 try utf8Error("\"\xdf\""); 1959 try utf8Error("\"\xed\xa0\""); 1960 try utf8Error("\"\xf0\x80\""); 1961 try utf8Error("\"\xf0\x80\x80\""); 1962} 1963 1964test "invalid continuation byte" { 1965 try utf8Error("\"\xc2\x00\""); 1966 try utf8Error("\"\xc2\x7f\""); 1967 try utf8Error("\"\xc2\xc0\""); 1968 try utf8Error("\"\xc3\xc1\""); 1969 try utf8Error("\"\xc4\xf5\""); 1970 try utf8Error("\"\xc5\xff\""); 1971 try utf8Error("\"\xe4\x80\x00\""); 1972 try utf8Error("\"\xe5\x80\x10\""); 1973 try utf8Error("\"\xe6\x80\xc0\""); 1974 try utf8Error("\"\xe7\x80\xf5\""); 1975 try utf8Error("\"\xe8\x00\x80\""); 1976 try utf8Error("\"\xf2\x00\x80\x80\""); 1977 try utf8Error("\"\xf0\x80\x00\x80\""); 1978 try utf8Error("\"\xf1\x80\xc0\x80\""); 1979 try utf8Error("\"\xf2\x80\x80\x00\""); 1980 try utf8Error("\"\xf3\x80\x80\xc0\""); 1981 try utf8Error("\"\xf4\x80\x80\xf5\""); 1982} 1983 1984test "disallowed overlong form" { 1985 try utf8Error("\"\xc0\x80\""); 1986 try utf8Error("\"\xc0\x90\""); 1987 try utf8Error("\"\xc1\x80\""); 1988 try utf8Error("\"\xc1\x90\""); 1989 try utf8Error("\"\xe0\x80\x80\""); 1990 try utf8Error("\"\xf0\x80\x80\x80\""); 1991} 1992 1993test "out of UTF-16 range" { 1994 try utf8Error("\"\xf4\x90\x80\x80\""); 1995 try utf8Error("\"\xf5\x80\x80\x80\""); 1996 try utf8Error("\"\xf6\x80\x80\x80\""); 1997 try utf8Error("\"\xf7\x80\x80\x80\""); 1998 try utf8Error("\"\xf8\x80\x80\x80\""); 1999 try utf8Error("\"\xf9\x80\x80\x80\""); 2000 try utf8Error("\"\xfa\x80\x80\x80\""); 2001 try utf8Error("\"\xfb\x80\x80\x80\""); 2002 try utf8Error("\"\xfc\x80\x80\x80\""); 2003 try utf8Error("\"\xfd\x80\x80\x80\""); 2004 try utf8Error("\"\xfe\x80\x80\x80\""); 2005 try utf8Error("\"\xff\x80\x80\x80\""); 2006} 2007