From 6d3b95a708c87ed81bd4f270b956913d82a0972d Mon Sep 17 00:00:00 2001 From: xackus <14938807+xackus@users.noreply.github.com> Date: Mon, 11 Nov 2019 23:41:53 +0100 Subject: [PATCH] Stricter tests for non-streaming parser --- lib/std/json/test.zig | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/std/json/test.zig b/lib/std/json/test.zig index cf33c337d9..2dc5b860ed 100644 --- a/lib/std/json/test.zig +++ b/lib/std/json/test.zig @@ -37,6 +37,18 @@ fn any(comptime s: []const u8) void { _ = p.parse(s) catch {}; } +fn anyStreamingErrNonStreaming(comptime s: []const u8) void { + _ = std.json.validate(s); + + var mem_buffer: [1024 * 20]u8 = undefined; + const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator; + var p = std.json.Parser.init(allocator, false); + + if(p.parse(s)) |_| { + unreachable; + } else |_| {} +} + //////////////////////////////////////////////////////////////////////////////////////////////////// // // Additional tests not part of test JSONTestSuite. @@ -1784,49 +1796,49 @@ test "i_number_very_big_negative_int" { } test "i_object_key_lone_2nd_surrogate" { - any( + anyStreamingErrNonStreaming( \\{"\uDFAA":0} ); } test "i_string_1st_surrogate_but_2nd_missing" { - any( + anyStreamingErrNonStreaming( \\["\uDADA"] ); } test "i_string_1st_valid_surrogate_2nd_invalid" { - any( + anyStreamingErrNonStreaming( \\["\uD888\u1234"] ); } test "i_string_incomplete_surrogate_and_escape_valid" { - any( + anyStreamingErrNonStreaming( \\["\uD800\n"] ); } test "i_string_incomplete_surrogate_pair" { - any( + anyStreamingErrNonStreaming( \\["\uDd1ea"] ); } test "i_string_incomplete_surrogates_escape_valid" { - any( + anyStreamingErrNonStreaming( \\["\uD800\uD800\n"] ); } test "i_string_invalid_lonely_surrogate" { - any( + anyStreamingErrNonStreaming( \\["\ud800"] ); } test "i_string_invalid_surrogate" { - any( + anyStreamingErrNonStreaming( \\["\ud800abc"] ); } @@ -1838,7 +1850,7 @@ test "i_string_invalid_utf-8" { } test "i_string_inverted_surrogates_U+1D11E" { - any( + anyStreamingErrNonStreaming( \\["\uDd1e\uD834"] ); } @@ -1850,7 +1862,7 @@ test "i_string_iso_latin_1" { } test "i_string_lone_second_surrogate" { - any( + anyStreamingErrNonStreaming( \\["\uDFAA"] ); }