Natools

Check-in [6f758d2e84]
Login
Overview
Comment:s_expressions-templates-tests-integers: test the new Render procedure with client-provided default format
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6f758d2e840ffd44338b77b11487e30d9e7d5066
User & Date: nat on 2014-09-21 20:14:04
Other Links: manifest | tags
Context
2014-09-23
18:33
s_expressions-templates-generic_integers: new command to add template-provided images for specific values (similar to discrete renderer) check-in: 7b85767e7d user: nat tags: trunk
2014-09-21
20:14
s_expressions-templates-tests-integers: test the new Render procedure with client-provided default format check-in: 6f758d2e84 user: nat tags: trunk
2014-09-20
21:50
s_expressions-templates-generic_integers: add a Render procedure with client-provided default format check-in: 0aeafdbf62 user: nat tags: trunk
Changes

Modified tests/natools-s_expressions-templates-tests-integers.adb from [b5f16abfc4] to [4fcbf5aa87].

18
19
20
21
22
23
24






25
26
27
28
29
30
31
with Natools.S_Expressions.Test_Tools;
with Natools.S_Expressions.Templates.Integers;
with Natools.Static_Maps.S_Expressions.Templates.Integers.T;

package body Natools.S_Expressions.Templates.Tests.Integers is

   procedure Test_Render






     (Test : in out NT.Test;
      Template : in String;
      Value : in Integer;
      Expected : in String);
      --  Run Template with Value and compare the result with Expected









>
>
>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
with Natools.S_Expressions.Test_Tools;
with Natools.S_Expressions.Templates.Integers;
with Natools.Static_Maps.S_Expressions.Templates.Integers.T;

package body Natools.S_Expressions.Templates.Tests.Integers is

   procedure Test_Render
     (Test : in out NT.Test;
      Defaults : in Templates.Integers.Format;
      Template : in String;
      Value : in Integer;
      Expected : in String);
   procedure Test_Render
     (Test : in out NT.Test;
      Template : in String;
      Value : in Integer;
      Expected : in String);
      --  Run Template with Value and compare the result with Expected


47
48
49
50
51
52
53



















54
55
56
57
58
59
60
61
62
63
64
65
66
67

68
69
70
71
72
73
74
      Parser.Next;
      Output.Set_Expected (To_Atom (Expected));
      Templates.Integers.Render (Output, Parser, Value);
      Output.Check_Stream (Test);
   end Test_Render;






















   -------------------------
   -- Complete Test Suite --
   -------------------------

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Alignment (Report);
      Default_Format (Report);
      Explicit_Sign (Report);
      Hexadecimal (Report);
      Overflow (Report);
      Parse_Errors (Report);
      Static_Hash_Map (Report);

   end All_Tests;


   -----------------------
   -- Inidividual Tests --
   -----------------------








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>














>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
      Parser.Next;
      Output.Set_Expected (To_Atom (Expected));
      Templates.Integers.Render (Output, Parser, Value);
      Output.Check_Stream (Test);
   end Test_Render;


   procedure Test_Render
     (Test : in out NT.Test;
      Defaults : in Templates.Integers.Format;
      Template : in String;
      Value : in Integer;
      Expected : in String)
   is
      Input : aliased Test_Tools.Memory_Stream;
      Output : Test_Tools.Memory_Stream;
      Parser : Parsers.Stream_Parser (Input'Access);
   begin
      Input.Set_Data (To_Atom (Template));
      Parser.Next;
      Output.Set_Expected (To_Atom (Expected));
      Templates.Integers.Render (Output, Defaults, Parser, Value);
      Output.Check_Stream (Test);
   end Test_Render;



   -------------------------
   -- Complete Test Suite --
   -------------------------

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Alignment (Report);
      Default_Format (Report);
      Explicit_Sign (Report);
      Hexadecimal (Report);
      Overflow (Report);
      Parse_Errors (Report);
      Static_Hash_Map (Report);
      Explicit_Default_Format (Report);
   end All_Tests;


   -----------------------
   -- Inidividual Tests --
   -----------------------

98
99
100
101
102
103
104


















105
106
107
108
109
110
111
      Test : NT.Test := Report.Item ("Debug instantiation");
   begin
      Test_Render (Test, "", 42, "42");
   exception
      when Error : others => Test.Report_Exception (Error);
   end Default_Format;




















   procedure Explicit_Sign (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Explicit sign specification");
   begin
      Test_Render (Test, "(sign +)", 42, "+42");
      Test_Render (Test, "(sign + _)", 42, "+42");
      Test_Render (Test, "(sign + _)", -42, "_42");







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
      Test : NT.Test := Report.Item ("Debug instantiation");
   begin
      Test_Render (Test, "", 42, "42");
   exception
      when Error : others => Test.Report_Exception (Error);
   end Default_Format;


   procedure Explicit_Default_Format (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Client-provided default format");
   begin
      declare
         Default : Templates.Integers.Format;
      begin
         Default.Set_Minimum_Width (2);
         Default.Set_Left_Padding (To_Atom ("0"));

         Test_Render (Test, Default, "", 5, "05");
         Test_Render (Test, Default, "", 12, "12");
         Test_Render (Test, Default, "(padding 1: )", 7, " 7");
      end;
   exception
      when Error : others => Test.Report_Exception (Error);
   end Explicit_Default_Format;


   procedure Explicit_Sign (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Explicit sign specification");
   begin
      Test_Render (Test, "(sign +)", 42, "+42");
      Test_Render (Test, "(sign + _)", 42, "+42");
      Test_Render (Test, "(sign + _)", -42, "_42");

Modified tests/natools-s_expressions-templates-tests-integers.ads from [9cefb81332] to [1757b59b20].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
package Natools.S_Expressions.Templates.Tests.Integers is
   pragma Preelaborate;

   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Alignment (Report : in out NT.Reporter'Class);
   procedure Default_Format (Report : in out NT.Reporter'Class);

   procedure Explicit_Sign (Report : in out NT.Reporter'Class);
   procedure Hexadecimal (Report : in out NT.Reporter'Class);
   procedure Overflow (Report : in out NT.Reporter'Class);
   procedure Parse_Errors (Report : in out NT.Reporter'Class);
   procedure Static_Hash_Map (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Templates.Tests.Integers;







>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package Natools.S_Expressions.Templates.Tests.Integers is
   pragma Preelaborate;

   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Alignment (Report : in out NT.Reporter'Class);
   procedure Default_Format (Report : in out NT.Reporter'Class);
   procedure Explicit_Default_Format (Report : in out NT.Reporter'Class);
   procedure Explicit_Sign (Report : in out NT.Reporter'Class);
   procedure Hexadecimal (Report : in out NT.Reporter'Class);
   procedure Overflow (Report : in out NT.Reporter'Class);
   procedure Parse_Errors (Report : in out NT.Reporter'Class);
   procedure Static_Hash_Map (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Templates.Tests.Integers;