Natools

Check-in [1bd9bb5772]
Login
Overview
Comment:string_slice_set_tests: add conversion and interval tests
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1bd9bb577218de7d78da0a26441f59373959c39e
User & Date: nat on 2013-10-07 19:12:35
Other Links: manifest | tags
Context
2013-10-08
21:21
string_slices: fix Is_Subrange so that any empty range is a subrange of any range check-in: 96a6d2d262 user: nat tags: trunk
2013-10-07
19:12
string_slice_set_tests: add conversion and interval tests check-in: 1bd9bb5772 user: nat tags: trunk
2013-10-06
20:38
chunked_strings: remove (hopefully) dead code in Chunked_String vs String comparison check-in: 2afdfab33b user: nat tags: trunk
Changes

Modified tests/natools-string_slice_set_tests.adb from [bfbaf590bc] to [5e09af406b].

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

   procedure Info_Fail
     (Report : in out NT.Reporter'Class;
      Name : in String;
      Reported : in out Boolean;
      Info : in String);
      --  Report failure if not already reported, and append Info
   pragma Unreferenced (Info_Fail);

   procedure Dump
     (Report : in out NT.Reporter'Class;
      Set : in Slice_Sets.Slice_Set);
      --  Dump the given slice set in Report.Info









<







31
32
33
34
35
36
37

38
39
40
41
42
43
44

   procedure Info_Fail
     (Report : in out NT.Reporter'Class;
      Name : in String;
      Reported : in out Boolean;
      Info : in String);
      --  Report failure if not already reported, and append Info


   procedure Dump
     (Report : in out NT.Reporter'Class;
      Set : in Slice_Sets.Slice_Set);
      --  Dump the given slice set in Report.Info


100
101
102
103
104
105
106


107
108
109
110
111
112
113
114
115




































































































































































































































































116
117
118
119
120
121
122

   ----------------------
   -- Test collections --
   ----------------------

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


      Test_Navigation (Report);
      Test_Tokenization (Report);
   end All_Tests;



   ----------------------
   -- Individual tests --
   ----------------------





































































































































































































































































   procedure Test_Navigation (Report : in out NT.Reporter'Class) is
      Name : constant String := "External index navigation";
   begin
      declare
         Set : Slice_Sets.Slice_Set := Slice_Sets.To_Slice_Set (Parent_String);
         Middle_First : constant Positive := 20;







>
>









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







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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

   ----------------------
   -- Test collections --
   ----------------------

   procedure All_Tests (Report : in out NT.Reporter'Class) is
   begin
      Test_Conversions (Report);
      Test_Interval_Arithmetic (Report);
      Test_Navigation (Report);
      Test_Tokenization (Report);
   end All_Tests;



   ----------------------
   -- Individual tests --
   ----------------------

   procedure Test_Conversions (Report : in out NT.Reporter'Class) is
      Name : constant String
        := "Conversions between slices, slice sets and strings";
      Reported : Boolean := False;
   begin
      declare
         use type String_Slices.Slice;
         use type Slice_Sets.Slice_Set;

         Parent_Slice : constant String_Slices.Slice
           := String_Slices.To_Slice (Parent_String);
         Range_1 : constant String_Slices.String_Range
           := (Parent_String'First, 10);
         Range_2 : constant String_Slices.String_Range
           := (Parent_String'Last - 9, 10);
         Range_3 : constant String_Slices.String_Range
           := String_Slices.To_Range
               (Parent_String'First + 6, Parent_String'Last - 7);
         Set : Slice_Sets.Slice_Set;
      begin
         if not Set.Is_Valid then
            Info_Fail (Report, Name, Reported, "Default set is invalid");
            Dump (Report, Set);
         end if;

         if not Set.Is_Null then
            Info_Fail (Report, Name, Reported, "Default set is not null");
            Dump (Report, Set);
         end if;

         if not Set.Is_Empty then
            Info_Fail (Report, Name, Reported, "Null set is not empty");
            Dump (Report, Set);
         end if;

         if Slice_Sets.To_Slice_Set (String_Slices.Null_Slice) /= Set then
            Info_Fail (Report, Name, Reported,
              "To_Slice_Set (Null_Slice) /= Null_Set");
         end if;

         if Set.To_Slice /= String_Slices.Null_Slice then
            Info_Fail (Report, Name, Reported,
              "To_Slice (Null_Set) /= Null_Slice");
         end if;

         if Set.To_String /= "" then
            Info_Fail (Report, Name, Reported, "To_String (Null_Set) /= """"");
         end if;

         Set := Slice_Sets.To_Slice_Set (Parent_Slice);
         Set.Clear;

         if Set.Is_Null then
            Info_Fail (Report, Name, Reported, "Cleared set is null");
         end if;

         if not Set.Is_Empty then
            Info_Fail (Report, Name, Reported, "Cleared set is not empty");
            Dump (Report, Set);
         end if;

         if Set.To_String /= "" then
            Info_Fail (Report, Name, Reported,
              "To_String (Empty_Set) /= """"");
         end if;

         if not String_Slices.Is_Subslice (Set.To_Slice, Parent_Slice) then
            Info_Fail (Report, Name, Reported,
              "To_Slice (Empty_Set) is not a subslice of parent.");
         end if;

         Set.Add_Slice (Range_1);

         if not Set.Is_Valid then
            Info_Fail (Report, Name, Reported, "Invalid slice singleton");
            Dump (Report, Set);
         end if;

         if Set.Is_Null then
            Info_Fail (Report, Name, Reported, "Slice singleton is null");
         end if;

         if Set.Is_Empty then
            Info_Fail (Report, Name, Reported, "Slice singleton is empty");
         end if;

         if Set.To_String
           /= Parent_String (Range_1.First .. String_Slices.Last (Range_1))
         then
            Info_Fail (Report, Name, Reported,
              "Found """ & Set.To_String & '"');
            Info_Fail (Report, Name, Reported, "Expected """
              & Parent_String (Range_1.First .. String_Slices.Last (Range_1))
              & '"');
            Dump (Report, Set);
         end if;

         if not String_Slices.Is_Subslice (Set.To_Slice, Parent_Slice) then
            Info_Fail (Report, Name, Reported,
               "To_Slice (Singleton) is not a subslice of parent.");
         end if;

         Set.Add_Slice (Range_2);

         if not Set.Is_Valid then
            Info_Fail (Report, Name, Reported, "Invalid normal set");
            Dump (Report, Set);
         end if;

         if Set.Is_Null then
            Info_Fail (Report, Name, Reported, "Normal set is null");
         end if;

         if Set.Is_Empty then
            Info_Fail (Report, Name, Reported, "Normal set is empty");
         end if;

         if Set.To_String
           /= Parent_String (Range_1.First .. String_Slices.Last (Range_1))
              & Parent_String (Range_2.First .. String_Slices.Last (Range_2))
         then
            Info_Fail (Report, Name, Reported,
              "Found """ & Set.To_String & '"');
            Info_Fail (Report, Name, Reported, "Expected """
              & Parent_String (Range_1.First .. String_Slices.Last (Range_1))
              & Parent_String (Range_2.First .. String_Slices.Last (Range_2))
              & '"');
            Dump (Report, Set);
         end if;

         if String_Slices.Is_Related (Set.To_Slice, Parent_Slice) then
            Info_Fail (Report, Name, Reported,
              "To_Slice (Complex_Set) related to parent slice");
            Dump (Report, Set);
         end if;

         if Set.To_String (Range_3)
           /= Parent_String (Range_3.First .. String_Slices.Last (Range_1))
              & Parent_String (Range_2.First .. String_Slices.Last (Range_3))
         then
            Info_Fail (Report, Name, Reported,
              "Found """ & Set.To_String (Range_3) & '"');
            Info_Fail (Report, Name, Reported, "Expected """
              & Parent_String (Range_3.First .. String_Slices.Last (Range_1))
              & Parent_String (Range_2.First .. String_Slices.Last (Range_3))
              & '"');
            Dump (Report, Set);
         end if;

         if Set.To_String (Range_3.First, String_Slices.Last (Range_3))
           /= Parent_String (Range_3.First .. String_Slices.Last (Range_1))
              & Parent_String (Range_2.First .. String_Slices.Last (Range_3))
         then
            Info_Fail (Report, Name, Reported, "Found """
              & Set.To_String (Range_3.First, String_Slices.Last (Range_3))
              & '"');
            Info_Fail (Report, Name, Reported, "Expected """
              & Parent_String (Range_3.First .. String_Slices.Last (Range_1))
              & Parent_String (Range_2.First .. String_Slices.Last (Range_3))
              & '"');
            Dump (Report, Set);
         end if;
      end;

      if not Reported then
         Report.Item (Name, NT.Success);
      end if;
   exception
      when Error : others => Report.Report_Exception (Name, Error);
   end Test_Conversions;

   procedure Test_Interval_Arithmetic (Report : in out NT.Reporter'Class) is
      Name : constant String := "Interval arithmetic";
      Reported : Boolean := False;

      procedure Check_Set
        (Parent : in String;
         Slices : in Slice_Sets.Slice_Set;
         Contents : in Ada.Strings.Maps.Character_Set);
         --  Check that slice inclusion is equivalent to character set

      procedure Check_Set
        (Parent : in String;
         Slices : in Slice_Sets.Slice_Set;
         Contents : in Ada.Strings.Maps.Character_Set)
      is
         Failure : Natural := 0;
      begin
         for I in Parent'Range loop
            if Ada.Strings.Maps.Is_In (Parent (I), Contents)
              /= Slices.Is_In (I)
            then
               Failure := I;
               exit;
            end if;
         end loop;

         if Failure > 0 then
            if not Reported then
               Report.Item (Name, NT.Fail);
               Reported := True;
            end if;

            Report.Info ("Expected set: "
              & Ada.Strings.Maps.To_Sequence (Contents));
            Dump (Report, Slices);
         end if;
      end Check_Set;
   begin
      declare
         Parent : constant String (11 .. 36)
           := "ABCDEFabc1234567890zyxWXYZ";
         --    123456789.123456789.123456
         Set : Slice_Sets.Slice_Set := Slice_Sets.To_Slice_Set (Parent);
      begin
         Set.Clear;
         Check_Set (Parent, Set, Ada.Strings.Maps.Null_Set);

         Set.Include_Slice (20, 29);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set ("0123456789"));

         Set.Include_Slice (20, 25);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set ("0123456789"));

         Set.Include_Slice (11, 16);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set ("0123456789ABCDEF"));

         Set.Include_Slice (14, 32);
         Check_Set (Parent, Set,
           Ada.Strings.Maps.To_Set ("0123456789ABCDEFabczyx"));

         Set.Include_Slice (33, 36);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set (Parent));

         Set.Exclude_Slice (20, 29);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set ("ABCDEFabczyxWXYZ"));

         Set.Include_Slice (27, 34);
         Check_Set (Parent, Set,
           Ada.Strings.Maps.To_Set ("ABCDEFabc890zyxWXYZ"));

         Set.Exclude_Slice (14, 13);
         Check_Set (Parent, Set,
           Ada.Strings.Maps.To_Set ("ABCDEFabc890zyxWXYZ"));

         Set.Exclude_Slice (5, 23);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set ("890zyxWXYZ"));

         Set.Include_Slice (13, 12);
         Check_Set (Parent, Set, Ada.Strings.Maps.To_Set ("890zyxWXYZ"));
      end;

      if not Reported then
         Report.Item (Name, NT.Success);
      end if;
   exception
      when Error : others => Report.Report_Exception (Name, Error);
   end Test_Interval_Arithmetic;


   procedure Test_Navigation (Report : in out NT.Reporter'Class) is
      Name : constant String := "External index navigation";
   begin
      declare
         Set : Slice_Sets.Slice_Set := Slice_Sets.To_Slice_Set (Parent_String);
         Middle_First : constant Positive := 20;

Modified tests/natools-string_slice_set_tests.ads from [16324aefd5] to [80f0378912].

24
25
26
27
28
29
30


31
32
33
34
package Natools.String_Slice_Set_Tests is
   pragma Preelaborate (String_Slice_Set_Tests);

   package NT renames Natools.Tests;

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



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

end Natools.String_Slice_Set_Tests;







>
>




24
25
26
27
28
29
30
31
32
33
34
35
36
package Natools.String_Slice_Set_Tests is
   pragma Preelaborate (String_Slice_Set_Tests);

   package NT renames Natools.Tests;

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

   procedure Test_Conversions (Report : in out NT.Reporter'Class);
   procedure Test_Interval_Arithmetic (Report : in out NT.Reporter'Class);
   procedure Test_Navigation (Report : in out NT.Reporter'Class);
   procedure Test_Tokenization (Report : in out NT.Reporter'Class);

end Natools.String_Slice_Set_Tests;