From 0e245c1eb61c8ccef82276536bb82b5ee8644594 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2026 09:53:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20test=20for=20missing=20com?= =?UTF-8?q?ma=20in=20JSON=20array=20and=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement a new unittest block in `source/djson/tests.d` to verify that `JSONSyntaxException` is thrown when a comma is missing between entries in JSON arrays and objects. - Covers lazy parsing (via `parseAll()`) - Covers eager parsing (via `parseJSONComplete()`) - Validates the error messages "Expected ',' between array entries" and "Expected ',' between object entries". Co-authored-by: trikko <647157+trikko@users.noreply.github.com> --- source/djson/tests.d | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source/djson/tests.d b/source/djson/tests.d index d90aa2b..c2fb4a7 100644 --- a/source/djson/tests.d +++ b/source/djson/tests.d @@ -984,3 +984,29 @@ unittest { json.append("!", "/hello/array"); assert(json.get!string("/hello/array/1") == "!"); } + +unittest { + // 27. Error conditions: missing commas + + // Missing comma in array (lazy) + auto lazyArr = parseJSON("[1 2]"); + auto e1 = collectException!JSONSyntaxException(lazyArr.parseAll()); + assert(e1 !is null); + assert(e1.msg == "Expected ',' between array entries"); + + // Missing comma in array (eager) + auto e2 = collectException!JSONSyntaxException(parseJSONComplete("[1 2]")); + assert(e2 !is null); + assert(e2.msg == "Expected ',' between array entries"); + + // Missing comma in object (lazy) + auto lazyObj = parseJSON(`{"a": 1 "b": 2}`); + auto e3 = collectException!JSONSyntaxException(lazyObj.parseAll()); + assert(e3 !is null); + assert(e3.msg == "Expected ',' between object entries"); + + // Missing comma in object (eager) + auto e4 = collectException!JSONSyntaxException(parseJSONComplete(`{"a": 1 "b": 2}`)); + assert(e4 !is null); + assert(e4.msg == "Expected ',' between object entries"); +}