Add data tests and fix code a little
M .hgignore +5 -0
@@ 8,3 8,8 @@ Adadir
 Adadir_bak
 TRACE.TMP
 ctst.bat
+objects
+tobjects
+doc/build
+results
+tester

          
M Makefile +16 -5
@@ 1,11 1,20 @@ 
+default: parser check
 
-all: parser
+all: default check
 
 parser: lib objects
-	gnatmake -g -Pjdaughter
+	gnatmake -p -Pjdaughter
+
+tester:
+	gnatmake -p -Pjdaughter_tests
 
-test: parser
-	./parser json.txt
+check: tester
+	./tester
+
+check_xml:
+	gnatmake -p -Pjdaughter_tests
+	mkdir -p results
+	./tester -x -d results
 
 lib:
 	mkdir -p lib

          
@@ 14,7 23,9 @@ objects:
 	mkdir -p objects
 
 clean:
-	gnatclean -Pjdaughter
+	-gnatclean -Pjdaughter
+	-gnatclean -Pjdaughter_tests
+	rm -rf results
 
 control: objects
 	rm -f objects/*.adt objects/*.ali

          
M doc/source/api-json.rst +3 -0
@@ 25,6 25,9 @@ with following code:
        Put_Line (Integer'Image (Multi_precision_integers.Basic (Val)));
     end;
 
+Jdaughter internally expects values to fit into Multi_int(20).
+If you need larger numbers, please modify the source code of Jdaughter.
+
 **JSON_Float**
 
     subtype JSON_Float is Float;

          
A => jdaughter_tests.gpr +43 -0
@@ 0,0 1,43 @@ 
+--
+-- Copyright (c) 2009 Tero Koskinen <tero.koskinen@iki.fi>
+--
+-- Permission to use, copy, modify, and distribute this software for any
+-- purpose with or without fee is hereby granted, provided that the above
+-- copyright notice and this permission notice appear in all copies.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+--
+
+with "ahven";
+with "hauki";
+
+project Jdaughter_Tests is
+
+  for Languages use ("Ada");
+  for Object_Dir use "tobjects";
+  -- for Library_Name use "jdaughter";
+  -- for Library_Dir use "lib";
+
+  for Source_Dirs use ("src", "test");
+  for Main use ("tester.adb");
+  for Exec_Dir use "./";
+
+  package Builder is
+     for Default_Switches ("Ada") use ("-g","-gnatf",
+                                       "-gnatVa",
+                                       "-gnato",
+                                       -- "-gnatwe",
+                                       -- "-gnatwa",
+                                       "-gnatwl",
+				       "-gnatE",
+                                       "-gnatwF", -- unreferenced formal off
+                                       "-gnatyd3ibmhex",
+				       "-gnat95");
+  end Builder;
+end Jdaughter_Tests;

          
M src/json-data.adb +14 -1
@@ 141,11 141,24 @@ package body JSON.Data is
    -- Number type
 
    function Create_Number (Value : JSON_Integer) return JSON_Number_Type is
+      Temp_Int : Multi_precision_integers.Multi_int(20);
    begin
+      Multi_precision_integers.Fill (what => Temp_Int, with_smaller => Value);
       return (Ada.Finalization.Controlled with
               Type_Kind   => JSON_NUMBER,
               Float_Type  => False,
-              Int_Value   => Value,
+              Int_Value   => Temp_Int,
+              Float_Value => 0.0);
+   end Create_Number;
+
+   function Create_Number (Value : Integer) return JSON_Number_Type is
+      Int_Val : Multi_precision_integers.Multi_int(20);
+   begin
+      Multi_precision_integers.Fill (Int_Val, Value);
+      return (Ada.Finalization.Controlled with
+              Type_Kind   => JSON_NUMBER,
+              Float_Type  => False,
+              Int_Value   => Int_Val,
               Float_Value => 0.0);
    end Create_Number;
 

          
M src/json-data.ads +3 -3
@@ 152,6 152,8 @@ package JSON.Data is
 
    function Create_Number (Value : JSON_Integer) return JSON_Number_Type;
 
+   function Create_Number (Value : Integer) return JSON_Number_Type;
+
    function Create_Number (Value : JSON_Float) return JSON_Number_Type;
 
    function Get_Value (Object : JSON_Number_Type) return JSON_Integer;

          
@@ 234,12 236,10 @@ private
       Value : Boolean;
    end record;
 
-   JSON_Integer_Size : constant := 20;
-
    type JSON_Number_Type is new JSON_Root_Type with record
       Float_Type : Boolean;
       Float_Value : JSON_Float;
-      Int_Value : JSON_Integer (JSON_Integer_Size);
+      Int_Value : JSON_Integer (JSON_Integer_N);
    end record;
 
    type JSON_String_Type is new JSON_Root_Type with record

          
M src/json-lexer.ads +1 -1
@@ 41,7 41,7 @@ package JSON.Lexer is
    type Token_Type is record
       Token_Kind : Token_Enum := INVALID_TOKEN;
       String_Value : Unbounded_String := Null_Unbounded_String;
-      Integer_Value : JSON_Integer (20);
+      Integer_Value : JSON_Integer (JSON_Integer_N);
       Float_Value : JSON_Float := 0.0;
    end record;
 

          
M src/json.ads +3 -0
@@ 19,4 19,7 @@ with Multi_precision_integers;
 package JSON is
    subtype JSON_Integer is Multi_precision_integers.Multi_int;
    subtype JSON_Float is Float;
+
+   JSON_Integer_N : constant := 20;
+   -- Jdaughter uses Multi_int (JSON_Integer_N) values internally.
 end JSON;

          
A => test/data_tests.adb +75 -0
@@ 0,0 1,75 @@ 
+--
+-- Copyright (c) 2010 Tero Koskinen <tero.koskinen@iki.fi>
+--
+-- Permission to use, copy, modify, and distribute this software for any
+-- purpose with or without fee is hereby granted, provided that the above
+-- copyright notice and this permission notice appear in all copies.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+--
+
+with Ahven;
+with JSON.Data;
+with JSON;
+with Multi_precision_integers;
+
+package body Data_Tests is
+   use Ahven;
+   use Ahven.Framework;
+   use type JSON.JSON_Integer;
+
+   procedure Initialize (T : in out Test) is
+   begin
+      Set_Name (T, "JSON.Data");
+      Add_Test_Routine (T, Test_Null_To_String'Access, "To_String (Null)");
+      Add_Test_Routine
+        (T, Test_Create_Integer'Access, "Create_Number (Integer)");
+      Add_Test_Routine
+        (T, Test_Create_Big_Integer'Access, "Create_Number (Big Integer)");
+   end Initialize;
+
+   procedure Test_Null_To_String is
+      Null_Object : JSON.Data.JSON_Null_Type := JSON.Data.Create_Null;
+      Null_Str : String := JSON.Data.To_String (Null_Object);
+   begin
+      Assert (Null_Str = "null", "Null_Str was: '" & Null_Str & "'");
+   end Test_Null_To_String;
+
+   procedure Test_Create_Integer is
+      use JSON.Data;
+      OBj : constant JSON.Data.JSON_Number_Type := Create_Number (10);
+      I   : constant JSON.JSON_Integer          := Get_Value (Obj);
+   begin
+      Assert (Multi_precision_integers.Basic (I) = 10, "value mismatch");
+   end Test_Create_Integer;
+
+   procedure Test_Create_Big_Integer is
+      use JSON.Data;
+
+      B : constant Multi_precision_integers.Basic_int :=
+            Multi_precision_integers.Basic_int'Last;
+      N : Multi_precision_integers.Multi_int(10);
+      I : JSON.JSON_Integer (20);
+   begin
+      -- N := B'Last;
+      -- N := N * B;
+      Multi_precision_integers.Fill (what => N, with_basic => B);
+      Multi_precision_integers.Multiply (i1 => N, i2 => B, i3 => N);
+
+      Multi_precision_integers.Fill (what => I,
+                                     with_smaller => N);
+      declare
+         Big_I : constant JSON.Data.JSON_Number_Type := Create_Number (I);
+      begin
+         Assert (Multi_precision_integers.Equal (Get_Value (Big_I), I),
+           "value mismatch");
+      end;
+   end Test_Create_Big_Integer;
+end Data_Tests;
+

          
A => test/data_tests.ads +27 -0
@@ 0,0 1,27 @@ 
+--
+-- Copyright (c) 2010 Tero Koskinen <tero.koskinen@iki.fi>
+--
+-- Permission to use, copy, modify, and distribute this software for any
+-- purpose with or without fee is hereby granted, provided that the above
+-- copyright notice and this permission notice appear in all copies.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+--
+
+with Ahven.Framework;
+
+package Data_Tests is
+   type Test is new Ahven.Framework.Test_Case with null record;
+
+   procedure Initialize (T : in out Test);
+private
+   procedure Test_Null_To_String;
+   procedure Test_Create_Integer;
+   procedure Test_Create_Big_Integer;
+end Data_Tests;

          
M test/tester.adb +2 -0
@@ 18,6 18,7 @@ 
 with Ahven.Text_Runner;
 with Ahven.Framework;
 with Parser_Tests;
+with Data_Tests;
 
 use Ahven;
 

          
@@ 25,5 26,6 @@ procedure Tester is
    S : Framework.Test_Suite := Framework.Create_Suite ("All");
 begin
    Framework.Add_Test (S, new Parser_Tests.Test);
+   Framework.Add_Test (S, new Data_Tests.Test);
    Text_Runner.Run (S);
 end Tester;