authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2019-11-11 23:41:53+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2019-11-11 23:41:53+01:00
log6d3b95a708c87ed81bd4f270b956913d82a0972d
tree5dc7534ae6ca4e4b0841ec30ae2bc781beaf4310
parentf9b7d6d75d24fa5844a6b83be312722d1a71efaf

Stricter tests for non-streaming parser


1 files changed, 22 insertions(+), 10 deletions(-)

lib/std/json/test.zig+22-10
...@@ -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}
3939
40fn 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}
17851797
1786test "i_object_key_lone_2nd_surrogate" {1798test "i_object_key_lone_2nd_surrogate" {
1787 any(1799 anyStreamingErrNonStreaming(
1788 \\{"\uDFAA":0}1800 \\{"\uDFAA":0}
1789 );1801 );
1790}1802}
17911803
1792test "i_string_1st_surrogate_but_2nd_missing" {1804test "i_string_1st_surrogate_but_2nd_missing" {
1793 any(1805 anyStreamingErrNonStreaming(
1794 \\["\uDADA"]1806 \\["\uDADA"]
1795 );1807 );
1796}1808}
17971809
1798test "i_string_1st_valid_surrogate_2nd_invalid" {1810test "i_string_1st_valid_surrogate_2nd_invalid" {
1799 any(1811 anyStreamingErrNonStreaming(
1800 \\["\uD888\u1234"]1812 \\["\uD888\u1234"]
1801 );1813 );
1802}1814}
18031815
1804test "i_string_incomplete_surrogate_and_escape_valid" {1816test "i_string_incomplete_surrogate_and_escape_valid" {
1805 any(1817 anyStreamingErrNonStreaming(
1806 \\["\uD800\n"]1818 \\["\uD800\n"]
1807 );1819 );
1808}1820}
18091821
1810test "i_string_incomplete_surrogate_pair" {1822test "i_string_incomplete_surrogate_pair" {
1811 any(1823 anyStreamingErrNonStreaming(
1812 \\["\uDd1ea"]1824 \\["\uDd1ea"]
1813 );1825 );
1814}1826}
18151827
1816test "i_string_incomplete_surrogates_escape_valid" {1828test "i_string_incomplete_surrogates_escape_valid" {
1817 any(1829 anyStreamingErrNonStreaming(
1818 \\["\uD800\uD800\n"]1830 \\["\uD800\uD800\n"]
1819 );1831 );
1820}1832}
18211833
1822test "i_string_invalid_lonely_surrogate" {1834test "i_string_invalid_lonely_surrogate" {
1823 any(1835 anyStreamingErrNonStreaming(
1824 \\["\ud800"]1836 \\["\ud800"]
1825 );1837 );
1826}1838}
18271839
1828test "i_string_invalid_surrogate" {1840test "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}
18391851
1840test "i_string_inverted_surrogates_U+1D11E" {1852test "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}
18511863
1852test "i_string_lone_second_surrogate" {1864test "i_string_lone_second_surrogate" {
1853 any(1865 anyStreamingErrNonStreaming(
1854 \\["\uDFAA"]1866 \\["\uDFAA"]
1855 );1867 );
1856}1868}