Commit 6d3b95a708

xackus <14938807+xackus@users.noreply.github.com>
2019-11-11 23:41:53
Stricter tests for non-streaming parser
1 parent f9b7d6d
Changed files (1)
lib
std
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"]
     );
 }