@@ 25,19 25,21 @@ with Multi_precision_integers;
package body Parser_Tests is
use Ahven;
-
+
-- Append double quotes around the string.
function Qt (Str : String) return String is
begin
return '"' & Str & '"';
end Qt;
-
+
procedure Initialize (T : in out Test) is
begin
Set_Name (T, "JSON.Parser");
Add_Test_Routine (T, Test_Parse_Number'Access, "Number");
Add_Test_Routine (T, Test_Parse_Invalid_Number'Access, "Number (invalid)");
Add_Test_Routine (T, Test_Parse_String'Access, "String");
+ Add_Test_Routine (T, Test_Parse_Invalid_Members_1'Access, "Invalid Members (1)");
+ Add_Test_Routine (T, Test_Parse_Empty_Object'Access, "Empty object");
end Initialize;
procedure Test_Parse_Number is
@@ 72,7 74,7 @@ package body Parser_Tests is
Fail ("Parse_Error expected");
exception
when JSON.Parser.Parse_Error =>
- null; -- expected
+ null; -- expected
end Test_Parse_Invalid_Number;
procedure Test_Parse_String is
@@ 91,4 93,35 @@ package body Parser_Tests is
null;
end;
end Test_Parse_String;
-end Parser_Tests;
No newline at end of file
+
+ procedure Test_Parse_Empty_Object is
+ S : Input.Unbounded_String_Stream;
+ H : JSON.Data.JSON_Holder.Holder;
+ begin
+ Input.Open (S, "{ }");
+ begin
+ JSON.Parser.Parse (Source => S, Object => H);
+ exception
+ when JSON.Parser.Parse_Error =>
+ Fail ("Valid input rejected");
+ end;
+ end Test_Parse_Empty_Object;
+
+ -- Try to parse following (invalid) data:
+ -- { "one" : ":1_1" , }
+ -- ^ notice comma here.
+ procedure Test_Parse_Invalid_Members_1 is
+ S : Input.Unbounded_String_Stream;
+ H : JSON.Data.JSON_Holder.Holder;
+ begin
+ Input.Open (S,
+ "{ " & Qt ("one") & ":" & Qt ("str") & " , }");
+ begin
+ JSON.Parser.Parse (Source => S, Object => H);
+ Fail ("Invalid input accepted");
+ exception
+ when JSON.Parser.Parse_Error =>
+ null; -- expected
+ end;
+ end Test_Parse_Invalid_Members_1;
+end Parser_Tests;
@@ 18,12 18,14 @@ with Ahven.Framework;
package Parser_Tests is
use Ahven.Framework;
-
+
type Test is new Test_Case with null record;
-
+
procedure Initialize (T : in out Test);
private
procedure Test_Parse_Number;
procedure Test_Parse_Invalid_Number;
procedure Test_Parse_String;
-end Parser_Tests;
No newline at end of file
+ procedure Test_Parse_Empty_Object;
+ procedure Test_Parse_Invalid_Members_1;
+end Parser_Tests;