| ... | @@ -37,6 +37,18 @@ fn any(comptime s: []const u8) void { | ... | @@ -37,6 +37,18 @@ fn any(comptime s: []const u8) void { |
| 37 | _ = p.parse(s) catch {}; | 37 | _ = p.parse(s) catch {}; |
| 38 | } | 38 | } |
| 39 | | 39 | |
| | 40 | fn anyStreamingErrNonStreaming(comptime s: []const u8) void { |
| | 41 | _ = std.json.validate(s); |
| | 42 | |
| | 43 | var mem_buffer: [1024 * 20]u8 = undefined; |
| | 44 | const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator; |
| | 45 | var p = std.json.Parser.init(allocator, false); |
| | 46 | |
| | 47 | if(p.parse(s)) |_| { |
| | 48 | unreachable; |
| | 49 | } else |_| {} |
| | 50 | } |
| | 51 | |
| 40 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 52 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 41 | // | 53 | // |
| 42 | // Additional tests not part of test JSONTestSuite. | 54 | // Additional tests not part of test JSONTestSuite. |
| ... | @@ -1784,49 +1796,49 @@ test "i_number_very_big_negative_int" { | ... | @@ -1784,49 +1796,49 @@ test "i_number_very_big_negative_int" { |
| 1784 | } | 1796 | } |
| 1785 | | 1797 | |
| 1786 | test "i_object_key_lone_2nd_surrogate" { | 1798 | test "i_object_key_lone_2nd_surrogate" { |
| 1787 | any( | 1799 | anyStreamingErrNonStreaming( |
| 1788 | \\{"\uDFAA":0} | 1800 | \\{"\uDFAA":0} |
| 1789 | ); | 1801 | ); |
| 1790 | } | 1802 | } |
| 1791 | | 1803 | |
| 1792 | test "i_string_1st_surrogate_but_2nd_missing" { | 1804 | test "i_string_1st_surrogate_but_2nd_missing" { |
| 1793 | any( | 1805 | anyStreamingErrNonStreaming( |
| 1794 | \\["\uDADA"] | 1806 | \\["\uDADA"] |
| 1795 | ); | 1807 | ); |
| 1796 | } | 1808 | } |
| 1797 | | 1809 | |
| 1798 | test "i_string_1st_valid_surrogate_2nd_invalid" { | 1810 | test "i_string_1st_valid_surrogate_2nd_invalid" { |
| 1799 | any( | 1811 | anyStreamingErrNonStreaming( |
| 1800 | \\["\uD888\u1234"] | 1812 | \\["\uD888\u1234"] |
| 1801 | ); | 1813 | ); |
| 1802 | } | 1814 | } |
| 1803 | | 1815 | |
| 1804 | test "i_string_incomplete_surrogate_and_escape_valid" { | 1816 | test "i_string_incomplete_surrogate_and_escape_valid" { |
| 1805 | any( | 1817 | anyStreamingErrNonStreaming( |
| 1806 | \\["\uD800\n"] | 1818 | \\["\uD800\n"] |
| 1807 | ); | 1819 | ); |
| 1808 | } | 1820 | } |
| 1809 | | 1821 | |
| 1810 | test "i_string_incomplete_surrogate_pair" { | 1822 | test "i_string_incomplete_surrogate_pair" { |
| 1811 | any( | 1823 | anyStreamingErrNonStreaming( |
| 1812 | \\["\uDd1ea"] | 1824 | \\["\uDd1ea"] |
| 1813 | ); | 1825 | ); |
| 1814 | } | 1826 | } |
| 1815 | | 1827 | |
| 1816 | test "i_string_incomplete_surrogates_escape_valid" { | 1828 | test "i_string_incomplete_surrogates_escape_valid" { |
| 1817 | any( | 1829 | anyStreamingErrNonStreaming( |
| 1818 | \\["\uD800\uD800\n"] | 1830 | \\["\uD800\uD800\n"] |
| 1819 | ); | 1831 | ); |
| 1820 | } | 1832 | } |
| 1821 | | 1833 | |
| 1822 | test "i_string_invalid_lonely_surrogate" { | 1834 | test "i_string_invalid_lonely_surrogate" { |
| 1823 | any( | 1835 | anyStreamingErrNonStreaming( |
| 1824 | \\["\ud800"] | 1836 | \\["\ud800"] |
| 1825 | ); | 1837 | ); |
| 1826 | } | 1838 | } |
| 1827 | | 1839 | |
| 1828 | test "i_string_invalid_surrogate" { | 1840 | test "i_string_invalid_surrogate" { |
| 1829 | any( | 1841 | anyStreamingErrNonStreaming( |
| 1830 | \\["\ud800abc"] | 1842 | \\["\ud800abc"] |
| 1831 | ); | 1843 | ); |
| 1832 | } | 1844 | } |
| ... | @@ -1838,7 +1850,7 @@ test "i_string_invalid_utf-8" { | ... | @@ -1838,7 +1850,7 @@ test "i_string_invalid_utf-8" { |
| 1838 | } | 1850 | } |
| 1839 | | 1851 | |
| 1840 | test "i_string_inverted_surrogates_U+1D11E" { | 1852 | test "i_string_inverted_surrogates_U+1D11E" { |
| 1841 | any( | 1853 | anyStreamingErrNonStreaming( |
| 1842 | \\["\uDd1e\uD834"] | 1854 | \\["\uDd1e\uD834"] |
| 1843 | ); | 1855 | ); |
| 1844 | } | 1856 | } |
| ... | @@ -1850,7 +1862,7 @@ test "i_string_iso_latin_1" { | ... | @@ -1850,7 +1862,7 @@ test "i_string_iso_latin_1" { |
| 1850 | } | 1862 | } |
| 1851 | | 1863 | |
| 1852 | test "i_string_lone_second_surrogate" { | 1864 | test "i_string_lone_second_surrogate" { |
| 1853 | any( | 1865 | anyStreamingErrNonStreaming( |
| 1854 | \\["\uDFAA"] | 1866 | \\["\uDFAA"] |
| 1855 | ); | 1867 | ); |
| 1856 | } | 1868 | } |