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 {
3737 _ = p.parse(s) catch {};
3838}
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
4052////////////////////////////////////////////////////////////////////////////////////////////////////
4153//
4254// Additional tests not part of test JSONTestSuite.
......@@ -1784,49 +1796,49 @@ test "i_number_very_big_negative_int" {
17841796}
17851797
17861798test "i_object_key_lone_2nd_surrogate" {
1787 any(
1799 anyStreamingErrNonStreaming(
17881800 \\{"\uDFAA":0}
17891801 );
17901802}
17911803
17921804test "i_string_1st_surrogate_but_2nd_missing" {
1793 any(
1805 anyStreamingErrNonStreaming(
17941806 \\["\uDADA"]
17951807 );
17961808}
17971809
17981810test "i_string_1st_valid_surrogate_2nd_invalid" {
1799 any(
1811 anyStreamingErrNonStreaming(
18001812 \\["\uD888\u1234"]
18011813 );
18021814}
18031815
18041816test "i_string_incomplete_surrogate_and_escape_valid" {
1805 any(
1817 anyStreamingErrNonStreaming(
18061818 \\["\uD800\n"]
18071819 );
18081820}
18091821
18101822test "i_string_incomplete_surrogate_pair" {
1811 any(
1823 anyStreamingErrNonStreaming(
18121824 \\["\uDd1ea"]
18131825 );
18141826}
18151827
18161828test "i_string_incomplete_surrogates_escape_valid" {
1817 any(
1829 anyStreamingErrNonStreaming(
18181830 \\["\uD800\uD800\n"]
18191831 );
18201832}
18211833
18221834test "i_string_invalid_lonely_surrogate" {
1823 any(
1835 anyStreamingErrNonStreaming(
18241836 \\["\ud800"]
18251837 );
18261838}
18271839
18281840test "i_string_invalid_surrogate" {
1829 any(
1841 anyStreamingErrNonStreaming(
18301842 \\["\ud800abc"]
18311843 );
18321844}
......@@ -1838,7 +1850,7 @@ test "i_string_invalid_utf-8" {
18381850}
18391851
18401852test "i_string_inverted_surrogates_U+1D11E" {
1841 any(
1853 anyStreamingErrNonStreaming(
18421854 \\["\uDd1e\uD834"]
18431855 );
18441856}
......@@ -1850,7 +1862,7 @@ test "i_string_iso_latin_1" {
18501862}
18511863
18521864test "i_string_lone_second_surrogate" {
1853 any(
1865 anyStreamingErrNonStreaming(
18541866 \\["\uDFAA"]
18551867 );
18561868}