mirror of https://github.com/Componolit/jwx
Use fixed-point instead of float numbers
This commit is contained in:
parent
5f87d336ec
commit
30380a0fd2
|
@ -54,7 +54,7 @@ begin
|
|||
Put_Line ("City: " & Get_String (Result)); -- "SAN FRANCISCO"
|
||||
|
||||
Result := Query_Object ("Latitude");
|
||||
Put_Line ("Lat.: " & Get_Float (Result)'Img); -- 37.7668
|
||||
Put_Line ("Lat.: " & Get_Real (Result)'Img); -- 37.7668
|
||||
end if;
|
||||
end JSON;
|
||||
```
|
||||
|
|
115
src/jwx-json.adb
115
src/jwx-json.adb
|
@ -27,10 +27,10 @@ is
|
|||
| Kind_Array => null;
|
||||
when Kind_Boolean =>
|
||||
Boolean_Value : Boolean := False;
|
||||
when Kind_Float =>
|
||||
Float_Value : Long_Float := 0.0;
|
||||
when Kind_Real =>
|
||||
Real_Value : Real_Type := 0.0;
|
||||
when Kind_Integer =>
|
||||
Integer_Value : Long_Integer := 0;
|
||||
Integer_Value : Integer_Type := 0;
|
||||
when Kind_String =>
|
||||
String_Start : Integer := 0;
|
||||
String_End : Integer := 0;
|
||||
|
@ -78,13 +78,13 @@ is
|
|||
Next_Value => Null_Index);
|
||||
|
||||
-------------------
|
||||
-- Float_Element --
|
||||
-- Real_Element --
|
||||
-------------------
|
||||
|
||||
function Float_Element (Value : Long_Float) return Context_Element_Type is
|
||||
-- Construct float element
|
||||
(Kind => Kind_Float,
|
||||
Float_Value => Value,
|
||||
function Real_Element (Value : Real_Type) return Context_Element_Type is
|
||||
-- Construct real element
|
||||
(Kind => Kind_Real,
|
||||
Real_Value => Value,
|
||||
Next_Member => Null_Index,
|
||||
Next_Value => Null_Index);
|
||||
|
||||
|
@ -92,7 +92,7 @@ is
|
|||
-- Integer_Element --
|
||||
---------------------
|
||||
|
||||
function Integer_Element (Value : Long_Integer) return Context_Element_Type is
|
||||
function Integer_Element (Value : Integer_Type) return Context_Element_Type is
|
||||
-- Construct integer element
|
||||
(Kind => Kind_Integer,
|
||||
Integer_Value => Value,
|
||||
|
@ -133,10 +133,11 @@ is
|
|||
|
||||
pragma Warnings (Off, "postcondition does not check the outcome of calling");
|
||||
|
||||
procedure Prf_Mult_Protect (Arg1 : Long_Integer;
|
||||
Arg2 : Long_Integer;
|
||||
Upper : Long_Integer)
|
||||
procedure Prf_Mult_Protect (Arg1 : Integer_Type;
|
||||
Arg2 : Integer_Type;
|
||||
Upper : Integer_Type)
|
||||
with
|
||||
Ghost,
|
||||
Global => null,
|
||||
Pre => (Arg1 >= 0 and Arg2 > 0 and Upper >= 0 and Arg1 < Upper)
|
||||
and then Arg1 <= Upper / Arg2,
|
||||
|
@ -144,9 +145,9 @@ is
|
|||
|
||||
pragma Warnings (On, "postcondition does not check the outcome of calling");
|
||||
|
||||
procedure Prf_Mult_Protect (Arg1 : Long_Integer;
|
||||
Arg2 : Long_Integer;
|
||||
Upper : Long_Integer) is null;
|
||||
procedure Prf_Mult_Protect (Arg1 : Integer_Type;
|
||||
Arg2 : Integer_Type;
|
||||
Upper : Integer_Type) is null;
|
||||
|
||||
---------
|
||||
-- Get --
|
||||
|
@ -224,25 +225,25 @@ is
|
|||
return Get (Index).Boolean_Value;
|
||||
end Get_Boolean;
|
||||
|
||||
---------------
|
||||
-- Get_Float --
|
||||
---------------
|
||||
--------------
|
||||
-- Get_Real --
|
||||
--------------
|
||||
|
||||
function Get_Float (Index : Index_Type := Null_Index) return Long_Float
|
||||
function Get_Real (Index : Index_Type := Null_Index) return Real_Type
|
||||
is
|
||||
begin
|
||||
if Get_Kind (Index) = Kind_Integer
|
||||
then
|
||||
return Long_Float (Get (Index).Integer_Value);
|
||||
return Real_Type (Get (Index).Integer_Value);
|
||||
end if;
|
||||
return Get (Index).Float_Value;
|
||||
end Get_Float;
|
||||
return Get (Index).Real_Value;
|
||||
end Get_Real;
|
||||
|
||||
-----------------
|
||||
-- Get_Integer --
|
||||
-----------------
|
||||
|
||||
function Get_Integer (Index : Index_Type := Null_Index) return Long_Integer
|
||||
function Get_Integer (Index : Index_Type := Null_Index) return Integer_Type
|
||||
is
|
||||
begin
|
||||
return Get (Index).Integer_Value;
|
||||
|
@ -398,7 +399,7 @@ is
|
|||
-- To_Number --
|
||||
---------------
|
||||
|
||||
function To_Number (Value : Character) return Long_Integer
|
||||
function To_Number (Value : Character) return Integer_Type
|
||||
is (Character'Pos (Value) - Character'Pos ('0'))
|
||||
with
|
||||
Pre => Value >= '0' and Value <= '9',
|
||||
|
@ -411,7 +412,7 @@ is
|
|||
|
||||
procedure Parse_Fractional_Part
|
||||
(Match : out Match_Type;
|
||||
Result : out Long_Float)
|
||||
Result : out Real_Type)
|
||||
with
|
||||
Pre =>
|
||||
Data'First < Integer'Last - Offset and
|
||||
|
@ -419,14 +420,14 @@ is
|
|||
Post =>
|
||||
(case Match is
|
||||
when Match_OK => Result >= 0.0 and Result < 1.0,
|
||||
when others => Offset = Offset'Old);
|
||||
when others => Result = 0.0 and Offset = Offset'Old);
|
||||
|
||||
procedure Parse_Fractional_Part
|
||||
(Match : out Match_Type;
|
||||
Result : out Long_Float)
|
||||
Result : out Real_Type)
|
||||
is
|
||||
Divisor : Long_Integer := 1;
|
||||
Tmp : Long_Integer := 0;
|
||||
Divisor : Integer_Type := 1;
|
||||
Tmp : Integer_Type := 0;
|
||||
Old_Offset : constant Natural := Offset;
|
||||
|
||||
begin
|
||||
|
@ -469,20 +470,21 @@ is
|
|||
exit;
|
||||
end if;
|
||||
|
||||
if Tmp >= Long_Integer'Last / 10
|
||||
if Tmp >= Integer_Type'Last / 10
|
||||
then
|
||||
Match := Match_Invalid;
|
||||
Offset := Old_Offset;
|
||||
return;
|
||||
end if;
|
||||
|
||||
Prf_Mult_Protect (Arg1 => Tmp,
|
||||
Arg2 => 10,
|
||||
Upper => Long_Integer'Last);
|
||||
Upper => Integer_Type'Last);
|
||||
|
||||
Tmp := 10 * Tmp + To_Number (Data (Data'First + Offset));
|
||||
Offset := Offset + 1;
|
||||
|
||||
if Divisor >= Long_Integer'Last / 10
|
||||
if Divisor >= Integer_Type'Last / 10
|
||||
then
|
||||
Match := Match_Invalid;
|
||||
Offset := Old_Offset;
|
||||
|
@ -495,8 +497,12 @@ is
|
|||
Match := Match_OK;
|
||||
end loop;
|
||||
|
||||
pragma Assert (Long_Float (Divisor) > Long_Float (Tmp));
|
||||
Result := Long_Float (Tmp) / Long_Float (Divisor);
|
||||
Result := Real_Type (Tmp) / Real_Type (Divisor);
|
||||
if Result >= 1.0 then
|
||||
Result := 0.0;
|
||||
Match := Match_Invalid;
|
||||
Offset := Old_Offset;
|
||||
end if;
|
||||
|
||||
end Parse_Fractional_Part;
|
||||
|
||||
|
@ -507,7 +513,7 @@ is
|
|||
procedure Parse_Integer
|
||||
(Check_Leading : Boolean;
|
||||
Match : out Match_Type;
|
||||
Result : out Long_Integer;
|
||||
Result : out Integer_Type;
|
||||
Negative : out Boolean)
|
||||
with
|
||||
Post => Result >= 0;
|
||||
|
@ -515,7 +521,7 @@ is
|
|||
procedure Parse_Integer
|
||||
(Check_Leading : Boolean;
|
||||
Match : out Match_Type;
|
||||
Result : out Long_Integer;
|
||||
Result : out Integer_Type;
|
||||
Negative : out Boolean)
|
||||
is
|
||||
Leading_Zero : Boolean := False;
|
||||
|
@ -575,7 +581,7 @@ is
|
|||
|
||||
-- Check for overflow
|
||||
if Num_Matches >= Natural'Last or
|
||||
Result >= Long_Integer'Last/10
|
||||
Result >= Integer_Type'Last/10
|
||||
then
|
||||
Match := Match_Invalid;
|
||||
Offset := Old_Offset;
|
||||
|
@ -614,7 +620,7 @@ is
|
|||
|
||||
procedure Parse_Exponent_Part
|
||||
(Match : out Match_Type;
|
||||
Result : out Long_Integer;
|
||||
Result : out Integer_Type;
|
||||
Negative : out Boolean)
|
||||
with
|
||||
Post => (case Match is
|
||||
|
@ -624,10 +630,10 @@ is
|
|||
|
||||
procedure Parse_Exponent_Part
|
||||
(Match : out Match_Type;
|
||||
Result : out Long_Integer;
|
||||
Result : out Integer_Type;
|
||||
Negative : out Boolean)
|
||||
is
|
||||
Scale : Long_Integer;
|
||||
Scale : Integer_Type;
|
||||
Match_Exponent : Match_Type;
|
||||
Integer_Negative : Boolean;
|
||||
Old_Offset : constant Natural := Offset;
|
||||
|
@ -678,7 +684,7 @@ is
|
|||
loop
|
||||
pragma Loop_Invariant (Result > 0);
|
||||
|
||||
if Result > Long_Integer'Last / 10
|
||||
if Result > Integer_Type'Last / 10
|
||||
then
|
||||
Offset := Old_Offset;
|
||||
return;
|
||||
|
@ -686,7 +692,7 @@ is
|
|||
|
||||
Prf_Mult_Protect (Arg1 => Result,
|
||||
Arg2 => 10,
|
||||
Upper => Long_Integer'Last);
|
||||
Upper => Integer_Type'Last);
|
||||
Result := Result * 10;
|
||||
end loop;
|
||||
|
||||
|
@ -700,9 +706,9 @@ is
|
|||
|
||||
procedure Parse_Number (Match : out Match_Type)
|
||||
is
|
||||
Fractional_Component : Long_Float := 0.0;
|
||||
Integer_Component : Long_Integer;
|
||||
Scale : Long_Integer;
|
||||
Fractional_Component : Real_Type := 0.0;
|
||||
Integer_Component : Integer_Type;
|
||||
Scale : Integer_Type;
|
||||
|
||||
Match_Int : Match_Type;
|
||||
Match_Frac : Match_Type := Match_None;
|
||||
|
@ -747,28 +753,31 @@ is
|
|||
(Match_Exponent = Match_OK and then
|
||||
(Scale_Negative and Integer_Component mod Scale > 0))
|
||||
then
|
||||
if Long_Float (Integer_Component) >= Long_Float'Last
|
||||
if Real_Type (Integer_Component) >= Real_Type'Last
|
||||
then
|
||||
return;
|
||||
end if;
|
||||
|
||||
declare
|
||||
Tmp : Long_Float := Long_Float (Integer_Component) + Fractional_Component;
|
||||
Tmp : Real_Type := Real_Type (Integer_Component) + Fractional_Component;
|
||||
begin
|
||||
if Match_Exponent = Match_OK
|
||||
then
|
||||
pragma Assert (Scale >= 1);
|
||||
if Scale_Negative
|
||||
then
|
||||
Tmp := Tmp / Long_Float (Scale);
|
||||
Tmp := Tmp / Real_Type (Scale);
|
||||
else
|
||||
Tmp := Tmp * Long_Float (Scale);
|
||||
if Tmp >= Real_Type'Last / Real_Type (Scale)
|
||||
then
|
||||
return;
|
||||
end if;
|
||||
Tmp := Tmp * Real_Type (Scale);
|
||||
end if;
|
||||
end if;
|
||||
if Negative then
|
||||
Tmp := -Tmp;
|
||||
end if;
|
||||
Set (Float_Element (Tmp));
|
||||
Set (Real_Element (Tmp));
|
||||
end;
|
||||
else
|
||||
if Match_Exponent = Match_OK
|
||||
|
@ -777,13 +786,13 @@ is
|
|||
then
|
||||
Integer_Component := Integer_Component / Scale;
|
||||
else
|
||||
if Integer_Component >= Long_Integer'Last / Scale
|
||||
if Integer_Component >= Integer_Type'Last / Scale
|
||||
then
|
||||
return;
|
||||
end if;
|
||||
Prf_Mult_Protect (Arg1 => Integer_Component,
|
||||
Arg2 => Scale,
|
||||
Upper => Long_Integer'Last);
|
||||
Upper => Integer_Type'Last);
|
||||
Integer_Component := Integer_Component * Scale;
|
||||
end if;
|
||||
end if;
|
||||
|
|
|
@ -29,7 +29,7 @@ is
|
|||
type Kind_Type is (Kind_Invalid,
|
||||
Kind_Null,
|
||||
Kind_Boolean,
|
||||
Kind_Float,
|
||||
Kind_Real,
|
||||
Kind_Integer,
|
||||
Kind_String,
|
||||
Kind_Object,
|
||||
|
@ -66,14 +66,14 @@ is
|
|||
with
|
||||
Pre => Get_Kind (Index) = Kind_Boolean;
|
||||
|
||||
-- Return value of float context element
|
||||
function Get_Float (Index : Index_Type := Null_Index) return Long_Float
|
||||
-- Return value of real context element
|
||||
function Get_Real (Index : Index_Type := Null_Index) return Real_Type
|
||||
with
|
||||
Pre => Get_Kind (Index) = Kind_Float or
|
||||
Pre => Get_Kind (Index) = Kind_Real or
|
||||
Get_Kind (Index) = Kind_Integer;
|
||||
|
||||
-- Return value of integer context element
|
||||
function Get_Integer (Index : Index_Type := Null_Index) return Long_Integer
|
||||
function Get_Integer (Index : Index_Type := Null_Index) return Integer_Type
|
||||
with
|
||||
Pre => Get_Kind (Index) = Kind_Integer;
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ is
|
|||
return;
|
||||
end if;
|
||||
|
||||
if Get_Integer (Value) < Now
|
||||
if Long_Integer (Get_Integer (Value)) < Now
|
||||
then
|
||||
return;
|
||||
end if;
|
||||
|
|
|
@ -17,6 +17,11 @@ is
|
|||
type Byte is mod 2**8
|
||||
with Size => 8;
|
||||
|
||||
type Integer_Type is range -2**46 .. 2**46 - 1;
|
||||
|
||||
type Real_Type is delta 0.00001 range Long_Float (Integer_Type'First) .. Long_Float (Integer_Type'Last)
|
||||
with Size => 64;
|
||||
|
||||
subtype Array_Index is Natural range Natural'First .. Natural'Last - 1;
|
||||
|
||||
type Byte_Array is array (Array_Index range <>) of Byte
|
||||
|
|
|
@ -256,8 +256,8 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = 123.45, "Invalid value: " & Get_Float'Img);
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = 123.45, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Num_With_Neg_Exp_Frac;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
@ -333,7 +333,7 @@ package body JWX_JSON_Tests is
|
|||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Small_Positive_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Small_Positive_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "3.14";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -342,13 +342,13 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = 3.14, "Invalid value: " & Get_Float'Img);
|
||||
end Test_Parse_Small_Positive_Float;
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = 3.14, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Small_Positive_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Small_Negative_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Small_Negative_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "-3.14";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -357,13 +357,13 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = -3.14, "Invalid value: " & Get_Float'Img);
|
||||
end Test_Parse_Small_Negative_Float;
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = -3.14, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Small_Negative_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Very_Small_Positive_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Very_Small_Positive_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "0.00000000001";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -372,13 +372,13 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = 0.00000000001, "Invalid value: " & Get_Float'Img);
|
||||
end Test_Parse_Very_Small_Positive_Float;
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = 0.00000000001, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Very_Small_Positive_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Too_Small_Positive_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Too_Small_Positive_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "0.0000000000000000000000000000000001";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -387,11 +387,11 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_Invalid, "Must fail: " & Match'Img);
|
||||
end Test_Parse_Too_Small_Positive_Float;
|
||||
end Test_Parse_Too_Small_Positive_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Very_Small_Negative_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Very_Small_Negative_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "-0.00000000001";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -400,13 +400,13 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = -0.00000000001, "Invalid value: " & Get_Float'Img);
|
||||
end Test_Parse_Very_Small_Negative_Float;
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = -0.00000000001, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Very_Small_Negative_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Too_Small_Negative_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Too_Small_Negative_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "-0.0000000000000000000000000000000001";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -415,11 +415,11 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_Invalid, "Must fail: " & Match'Img);
|
||||
end Test_Parse_Too_Small_Negative_Float;
|
||||
end Test_Parse_Too_Small_Negative_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Zero_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Zero_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := " 0.0 ";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -428,13 +428,13 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = 0.0, "Invalid value: " & Get_Float'Img);
|
||||
end Test_Parse_Zero_Float;
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = 0.0, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Zero_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Parse_Float_With_Exp_With_Leading_Zero (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Parse_Real_With_Exp_With_Leading_Zero (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "123.5e+02";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -443,9 +443,9 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_OK, "No match: " & Match'Img);
|
||||
Assert (Get_Kind = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float = 12350.0, "Invalid value: " & Get_Float'Img);
|
||||
end Test_Parse_Float_With_Exp_With_Leading_Zero;
|
||||
Assert (Get_Kind = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real = 12350.0, "Invalid value: " & Get_Real'Img);
|
||||
end Test_Parse_Real_With_Exp_With_Leading_Zero;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
|
@ -462,7 +462,7 @@ package body JWX_JSON_Tests is
|
|||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
procedure Test_Leading_Zero_Float (T : in out Test_Cases.Test_Case'Class)
|
||||
procedure Test_Leading_Zero_Real (T : in out Test_Cases.Test_Case'Class)
|
||||
is
|
||||
Data : String := "000.06854";
|
||||
package J is new JWX.JSON (Data);
|
||||
|
@ -471,7 +471,7 @@ package body JWX_JSON_Tests is
|
|||
begin
|
||||
Parse (Match);
|
||||
Assert (Match = Match_Invalid, "Must fail: " & Match'Img);
|
||||
end Test_Leading_Zero_Float;
|
||||
end Test_Leading_Zero_Real;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
|
@ -580,12 +580,12 @@ package body JWX_JSON_Tests is
|
|||
Assert (Get_String (Result) = "zip", "Invalid string: " & Get_String (Result));
|
||||
|
||||
Result := Query_Object ("Latitude");
|
||||
Assert (Get_Kind (Result) = Kind_Float, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
Assert (Get_Float (Result) = 37.7668, "Invalid float: " & Get_Float (Result)'Img);
|
||||
Assert (Get_Kind (Result) = Kind_Real, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
Assert (Get_Real (Result) = 37.7668, "Invalid real: " & Get_Real (Result)'Img);
|
||||
|
||||
Result := Query_Object ("Longitude");
|
||||
Assert (Get_Kind (Result) = Kind_Float, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
Assert (Get_Float (Result) = -122.3959, "Invalid float: " & Get_Float (Result)'Img);
|
||||
Assert (Get_Kind (Result) = Kind_Real, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
Assert (Get_Real (Result) = -122.3959, "Invalid real: " & Get_Real (Result)'Img);
|
||||
|
||||
Result := Query_Object ("Address");
|
||||
Assert (Get_Kind (Result) = Kind_String, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
|
@ -698,8 +698,8 @@ package body JWX_JSON_Tests is
|
|||
Assert (Get_Integer (Result) = 116, "Invalid value: " & Get_Integer (Result)'Img);
|
||||
|
||||
Result := Pos (2);
|
||||
Assert (Get_Kind (Result) = Kind_Float, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
Assert (Get_Float (Result) = -4.5, "Invalid value: " & Get_Float (Result)'Img);
|
||||
Assert (Get_Kind (Result) = Kind_Real, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
Assert (Get_Real (Result) = -4.5, "Invalid value: " & Get_Real (Result)'Img);
|
||||
|
||||
Result := Pos (3);
|
||||
Assert (Get_Kind (Result) = Kind_String, "Invalid kind: " & Get_Kind (Result)'Img);
|
||||
|
@ -787,8 +787,8 @@ package body JWX_JSON_Tests is
|
|||
Assert (Elements = 20, "Invalid number of elements: " & Elements'Img);
|
||||
|
||||
Result := Query_Object ("area");
|
||||
Assert (Get_Kind (Result) = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (abs (Get_Float (Result) - 1246700.0) < Float'Epsilon, "Invalid value: " & Get_Float (Result)'Img);
|
||||
Assert (Get_Kind (Result) = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real (Result) /= 1246700.0, "Invalid value: " & Get_Real (Result)'Img);
|
||||
end Test_Complex_Country;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
@ -810,8 +810,8 @@ package body JWX_JSON_Tests is
|
|||
Assert (Elements (Result) = 1, "Invalid number of elements: " & Elements (Result)'Img);
|
||||
|
||||
Result := Query_Object ("area", Result);
|
||||
Assert (Get_Kind (Result) = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Float (Result) = 123.0, "Invalid value: " & Get_Float (Result)'Img);
|
||||
Assert (Get_Kind (Result) = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real (Result) = 123.0, "Invalid value: " & Get_Real (Result)'Img);
|
||||
end Test_Mixed_Objects;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
@ -835,8 +835,8 @@ package body JWX_JSON_Tests is
|
|||
|
||||
Result := Query_Object ("area", Result);
|
||||
Assert (Result /= Null_Index, "Element not found");
|
||||
Assert (Get_Kind (Result) = Kind_Float, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (abs (Get_Float (Result) - 1246700.0) < Float'Epsilon, "Invalid value: " & Get_Float (Result)'Img);
|
||||
Assert (Get_Kind (Result) = Kind_Real, "Invalid kind: " & Get_Kind'Img);
|
||||
Assert (Get_Real (Result) /= 1246700.0, "Invalid value: " & Get_Real (Result)'Img);
|
||||
end Test_Complex_Two_Countries;
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
@ -935,16 +935,16 @@ package body JWX_JSON_Tests is
|
|||
Register_Routine (T, Test_Parse_Big_Negative_Integer'Access, "Parse big negative integer");
|
||||
Register_Routine (T, Test_Parse_Too_Big_Integer'Access, "Too big integer");
|
||||
Register_Routine (T, Test_Parse_Too_Small_Integer 'Access, "Too small integer");
|
||||
Register_Routine (T, Test_Parse_Small_Positive_Float'Access, "Parse small positive float");
|
||||
Register_Routine (T, Test_Parse_Small_Negative_Float 'Access, "Parse small negative float");
|
||||
Register_Routine (T, Test_Parse_Very_Small_Positive_Float'Access, "Parse very small positive float");
|
||||
Register_Routine (T, Test_Parse_Too_Small_Positive_Float'Access, "Too small positive float");
|
||||
Register_Routine (T, Test_Parse_Very_Small_Negative_Float'Access, "Parse very small negative float");
|
||||
Register_Routine (T, Test_Parse_Too_Small_Negative_Float'Access, "Too small negative float");
|
||||
Register_Routine (T, Test_Parse_Zero_Float'Access, "Parse zero float");
|
||||
Register_Routine (T, Test_Parse_Float_With_Exp_With_Leading_Zero'Access, "Parse float with exponent with leading zero");
|
||||
Register_Routine (T, Test_Parse_Small_Positive_Real'Access, "Parse small positive real");
|
||||
Register_Routine (T, Test_Parse_Small_Negative_Real 'Access, "Parse small negative real");
|
||||
Register_Routine (T, Test_Parse_Very_Small_Positive_Real'Access, "Parse very small positive real");
|
||||
Register_Routine (T, Test_Parse_Too_Small_Positive_Real'Access, "Too small positive real");
|
||||
Register_Routine (T, Test_Parse_Very_Small_Negative_Real'Access, "Parse very small negative real");
|
||||
Register_Routine (T, Test_Parse_Too_Small_Negative_Real'Access, "Too small negative real");
|
||||
Register_Routine (T, Test_Parse_Zero_Real'Access, "Parse zero real");
|
||||
Register_Routine (T, Test_Parse_Real_With_Exp_With_Leading_Zero'Access, "Parse real with exponent with leading zero");
|
||||
Register_Routine (T, Test_Leading_Zero_Integer'Access, "Integer with leading zero");
|
||||
Register_Routine (T, Test_Leading_Zero_Float 'Access, "Float with leading zero");
|
||||
Register_Routine (T, Test_Leading_Zero_Real 'Access, "Real with leading zero");
|
||||
Register_Routine (T, Test_Missing_Fractional_Part 'Access, "Missing fractional part");
|
||||
Register_Routine (T, Test_Simple_String'Access, "Parse simple string");
|
||||
Register_Routine (T, Test_Unclosed_String'Access, "Unclosed string");
|
||||
|
|
Loading…
Reference in New Issue