Natools

Check-in [51d9aa70ca]
Login
Overview
Comment:s_expressions-templates-tests-dates: test suite for date S-exrepssion templates
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 51d9aa70ca7c3bf3b3fbe0bec6858af55aaa54cf
User & Date: nat on 2014-10-04 20:34:35
Other Links: manifest | tags
Context
2014-10-05
16:24
README: add a short description of recently-added packages check-in: 73c9e491df user: nat tags: trunk
2014-10-04
20:34
s_expressions-templates-tests-dates: test suite for date S-exrepssion templates check-in: 51d9aa70ca user: nat tags: trunk
2014-10-03
21:04
s_expressions-templates-dates: new package for date template rendering check-in: f65011d51a user: nat tags: trunk
Changes

Added tests/natools-s_expressions-templates-tests-dates.adb version [095f17d300].























































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- 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 Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones;
with Natools.S_Expressions.Parsers;
with Natools.S_Expressions.Test_Tools;
with Natools.S_Expressions.Templates.Dates;
with Natools.Static_Maps.S_Expressions.Templates.Dates.T;

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

   procedure Test_Render
     (Test : in out NT.Test;
      Template : in String;
      Expected : in String;
      Value : in Ada.Calendar.Time;
      Time_Zone : Ada.Calendar.Time_Zones.Time_Offset := 0);
      --  Run Template with Value and compare the result with Expected


   ------------------------------
   -- Local Helper Subprograms --
   ------------------------------

   procedure Test_Render
     (Test : in out NT.Test;
      Template : in String;
      Expected : in String;
      Value : in Ada.Calendar.Time;
      Time_Zone : Ada.Calendar.Time_Zones.Time_Offset := 0)
   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.Dates.Render (Output, Parser, Value, Time_Zone);
      Output.Check_Stream (Test);
   end Test_Render;



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

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Composite_Components (Report);
      Padded_Components (Report);
      RFC_3339 (Report);
      Simple_Components (Report);
      Static_Hash_Map (Report);
   end All_Tests;


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

   procedure Composite_Components (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Composite date and time formats");
   begin
      Test_Render
        (Test, "(YYYYMMDD)T(HHMMSS)",
         "20111125T082052",
         Ada.Calendar.Formatting.Time_Of (2011, 11, 25, 8, 20, 52));
      Test_Render
        (Test, "(big-endian-date ""."")1: (time "":"")",
         "2013.10.01 18:49:11",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 1, 18, 49, 11));
      Test_Render
        (Test, "(little-endian-date ""/"")1: (time h m)1:s",
         "11/10/2013 21h51m08s",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 11, 21, 51, 8));
      Test_Render
        (Test, "(big-endian-date 1: 1: )2:, (little-endian-time 1:;)",
         "2013 10 13, 00;47;15",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 13, 15, 47, 0));
      Test_Render
        (Test, "(SSMMHH)(DDMMYYYY)",
         "01082129012014",
         Ada.Calendar.Formatting.Time_Of (2014, 1, 29, 21, 8, 1));
   exception
      when Error : others => Test.Report_Exception (Error);
   end Composite_Components;


   procedure Padded_Components (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Simple time components with padding");
      Template : constant String
        := "(padded-month)(padded-day)(padded-hour)(minute)(padded-second)";
   begin
      Test_Render
        (Test, Template,
         "1125082052",
         Ada.Calendar.Formatting.Time_Of (2011, 11, 25, 8, 20, 52));
      Test_Render
        (Test, Template,
         "1001184911",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 1, 18, 49, 11));
      Test_Render
        (Test, Template,
         "1011215108",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 11, 21, 51, 8));
      Test_Render
        (Test, Template,
         "1013154700",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 13, 15, 47, 0));
      Test_Render
        (Test, Template,
         "012921801",
         Ada.Calendar.Formatting.Time_Of (2014, 1, 29, 21, 8, 1));
   exception
      when Error : others => Test.Report_Exception (Error);
   end Padded_Components;


   procedure RFC_3339 (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("RFC-3339 format");
   begin
      Test_Render
        (Test, "(rfc-3339)",
         "2011-11-25T08:20:52Z",
         Ada.Calendar.Formatting.Time_Of (2011, 11, 25, 8, 20, 52));
      Test_Render
        (Test, "(rfc-3339)",
         "2013-10-01T18:49:11Z",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 1, 18, 49, 11));
      Test_Render
        (Test, "(rfc-3339)",
         "2013-10-11T21:51:08Z",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 11, 21, 51, 8));
      Test_Render
        (Test, "(rfc-3339)",
         "2013-10-13T15:47:00Z",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 13, 15, 47, 0));
      Test_Render
        (Test, "(rfc-3339)",
         "2014-01-29T21:08:01Z",
         Ada.Calendar.Formatting.Time_Of (2014, 1, 29, 21, 8, 1));
   exception
      when Error : others => Test.Report_Exception (Error);
   end RFC_3339;


   procedure Simple_Components (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Simple time components");
      Template : constant String
        := "3:Le "
         & "(day-of-week lundi mardi mercredi jeudi vendredi samedi dimanche)"
         & "1: "
         & "(day (suffix (er 1)))"
         & "1: "
         & "(month janvier février mars avril mai juin juillet"
         & " août septembre octobre novembre décembre)"
         & "1: (year)"
         & """ à """
         & "(hour) 1:h (padded-minute)"
         & "4: et (second)"
         & "1: (second (image-range secondes (seconde 1 0)))";
   begin
      Test_Render
        (Test, Template,
         "Le vendredi 25 novembre 2011 à 8h20 et 52 secondes",
         Ada.Calendar.Formatting.Time_Of (2011, 11, 25, 8, 20, 52));
      Test_Render
        (Test, Template,
         "Le mardi 1er octobre 2013 à 18h49 et 11 secondes",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 1, 18, 49, 11));
      Test_Render
        (Test, Template,
         "Le vendredi 11 octobre 2013 à 21h51 et 8 secondes",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 11, 21, 51, 8));
      Test_Render
        (Test, Template,
         "Le dimanche 13 octobre 2013 à 15h47 et 0 seconde",
         Ada.Calendar.Formatting.Time_Of (2013, 10, 13, 15, 47, 0));
      Test_Render
        (Test, Template,
         "Le mercredi 29 janvier 2014 à 21h08 et 1 seconde",
         Ada.Calendar.Formatting.Time_Of (2014, 1, 29, 21, 8, 1));
   exception
      when Error : others => Test.Report_Exception (Error);
   end Simple_Components;


   procedure Static_Hash_Map (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Parse errors in template");
   begin
      if not Natools.Static_Maps.S_Expressions.Templates.Dates.T then
         Test.Fail;
      end if;
   exception
      when Error : others => Test.Report_Exception (Error);
   end Static_Hash_Map;

end Natools.S_Expressions.Templates.Tests.Dates;

Added tests/natools-s_expressions-templates-tests-dates.ads version [6a7301fba4].

































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- 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.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.S_Expressions.Templates.Tests.Dates provides a test suite for    --
-- date S-expression template system.                                       --
------------------------------------------------------------------------------

package Natools.S_Expressions.Templates.Tests.Dates is

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

   procedure Composite_Components (Report : in out NT.Reporter'Class);
   procedure Padded_Components (Report : in out NT.Reporter'Class);
   procedure RFC_3339 (Report : in out NT.Reporter'Class);
   procedure Simple_Components (Report : in out NT.Reporter'Class);
   procedure Static_Hash_Map (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Templates.Tests.Dates;

Modified tests/natools-s_expressions-templates-tests-integers.ads from [1b0e2b84dc] to [96661e79d1].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
16
17
18
19
20
21
22

23
24
25
26
27
28
29







-








------------------------------------------------------------------------------
-- Natools.S_Expressions.Templates.Tests.Integers provides a test suite for --
-- integer S-expression template system.                                    --
------------------------------------------------------------------------------

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_Images (Report : in out NT.Reporter'Class);

Modified tests/natools-s_expressions-templates-tests.adb from [c58c6a5938] to [dad8e6621b].

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43








44
45
46
47
48
49
50
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60







+
















+








+
+
+
+
+
+
+
+







-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

with Natools.S_Expressions.Parsers;
with Natools.S_Expressions.Templates.Generic_Discrete_Render;
with Natools.S_Expressions.Templates.Tests.Integers;
with Natools.S_Expressions.Templates.Tests.Dates;
with Natools.S_Expressions.Test_Tools;

package body Natools.S_Expressions.Templates.Tests is

   type Day_Name is (Monday, Tuesday, Wednesday, Thursday,
       Friday, Saturday, Sunday);

   procedure Day_Render is new Generic_Discrete_Render (Day_Name);


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

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Test_Date (Report);
      Test_Discrete (Report);
      Test_Integers (Report);
   end All_Tests;


   --------------------------------------
   -- Inidividual Children Test Suites --
   --------------------------------------

   procedure Test_Date (Report : in out NT.Reporter'Class) is
   begin
      Report.Section ("Date templates");
      Natools.S_Expressions.Templates.Tests.Dates.All_Tests (Report);
      Report.End_Section;
   end Test_Date;


   procedure Test_Discrete (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Discrete templates");

      procedure Render_Test
        (Template : in String;
         Value : in Day_Name;

Modified tests/natools-s_expressions-templates-tests.ads from [346e2b4a31] to [772c70e6ef].

18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34







-





+




-- Natools.S_Expressions.Templates.Tests gathers all test suites for the    --
-- S-expression template systems.                                           --
------------------------------------------------------------------------------

with Natools.Tests;

package Natools.S_Expressions.Templates.Tests is
   pragma Preelaborate;

   package NT renames Natools.Tests;

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

   procedure Test_Date (Report : in out NT.Reporter'Class);
   procedure Test_Discrete (Report : in out NT.Reporter'Class);
   procedure Test_Integers (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Templates.Tests;