From 77d0d110060ab03b7e8a706ea6cc9404e22c13f4 Mon Sep 17 00:00:00 2001 From: Jerome Lambourg Date: Mon, 14 Oct 2024 14:22:13 +0200 Subject: [PATCH] Add test for the SAX-like JSON parser. --- testsuite/tests/json/api/test.adb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testsuite/tests/json/api/test.adb b/testsuite/tests/json/api/test.adb index b5358b37..f544de8a 100644 --- a/testsuite/tests/json/api/test.adb +++ b/testsuite/tests/json/api/test.adb @@ -1,5 +1,6 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with GNAT.Source_Info; +with GNATCOLL.Buffer; use GNATCOLL.Buffer; with GNATCOLL.JSON; use GNATCOLL.JSON; with GNATCOLL.Strings; use GNATCOLL.Strings; @@ -190,6 +191,25 @@ begin Check_Error (Read ("{"), "1:1: string expected"); Check_Error (Read (To_Unbounded_String ("{")), "1:1: string expected"); + declare + Parser : JSON_Parser; + Buff : Reader := Open_String ("{""key"": ""\u0041\u0042""}"); + Event : JSON_Parser_Event; + begin + Event := Parser.Parse_Next (Buff); + A.Assert (Event.Kind = OBJECT_START); + Event := Parser.Parse_Next (Buff); + A.Assert (Event.Kind = STRING_VALUE); + A.Assert (Decode_As_String (Event, Buff) = "key"); + Event := Parser.Parse_Next (Buff); + A.Assert (Event.Kind = STRING_VALUE); + A.Assert (Decode_As_String (Event, Buff) = "AB"); + Event := Parser.Parse_Next (Buff); + A.Assert (Event.Kind = OBJECT_END); + Event := Parser.Parse_Next (Buff); + A.Assert (Event.Kind = DOC_END); + end; + ----------------------------- -- Creation of JSON values -- -----------------------------