3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that procedures defined in package Ada.Strings.Unbounded
28 -- are available, and that they produce correct results. Specifically,
29 -- check the procedures Replace_Slice, Insert, Overwrite, Delete,
30 -- Trim (2 versions), Head, and Tail.
33 -- This test demonstrates the uses of many of the procedures defined
34 -- in package Ada.Strings.Unbounded for use with unbounded strings.
35 -- The test simulates how unbounded strings could be processed in a
36 -- user environment, using the procedures provided in this package.
38 -- This test, when taken in conjunction with tests CXA4010, CXA4011,
39 -- CXA4030, and CXA4031 will constitute a test of all the functionality
40 -- contained in package Ada.Strings.Unbounded. This test uses a variety
41 -- of the procedures defined in the unbounded string package in ways
42 -- typical of common usage.
46 -- 02 Mar 95 SAIC Initial prerelease version.
52 with Ada
.Strings
.Maps
;
53 with Ada
.Strings
.Maps
.Constants
;
54 with Ada
.Strings
.Unbounded
;
59 Report
.Test
("CXA4032", "Check that the subprograms defined in " &
60 "package Ada.Strings.Unbounded are available, " &
61 "and that they produce correct results");
66 package Unb
renames Ada
.Strings
.Unbounded
;
70 TC_Null_String
: constant String := "";
71 TC_String_5
: String(1..5) := "ABCDE";
73 TC_Unb_String
: Unb
.Unbounded_String
:=
74 Unb
.To_Unbounded_String
("Test String");
78 -- Procedure Replace_Slice
80 begin -- Low > Source'Last+1
81 Unb
.Replace_Slice
(Source
=> TC_Unb_String
,
82 Low
=> Unb
.Length
(TC_Unb_String
) + 2,
83 High
=> Unb
.Length
(TC_Unb_String
),
85 Report
.Failed
("Index_Error not raised by Replace_Slice when Low " &
88 when Index_Error
=> null; -- OK, expected exception.
90 Report
.Failed
("Unexpected exception raised by Replace_Slice" &
91 "when Low > Source'Last+1");
96 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
98 Unb
.Replace_Slice
(TC_Unb_String
, 5, 5, TC_String_5
);
100 if TC_Unb_String
/= Unb
.To_Unbounded_String
("TestABCDEString") then
101 Report
.Failed
("Incorrect results from Replace_Slice - 1");
104 Unb
.Replace_Slice
(TC_Unb_String
, 1, 4, TC_String_5
);
106 if TC_Unb_String
/= Unb
.To_Unbounded_String
("ABCDEABCDEString") then
107 Report
.Failed
("Incorrect results from Replace_Slice - 2");
110 Unb
.Replace_Slice
(TC_Unb_String
,
112 Unb
.Length
(TC_Unb_String
),
115 if TC_Unb_String
/= Unb
.To_Unbounded_String
("ABCDEABCDE") then
116 Report
.Failed
("Incorrect results from Replace_Slice - 3");
121 Unb
.Replace_Slice
(TC_Unb_String
, Low
=> 4, High
=> 1, By
=> "xxx");
123 if TC_Unb_String
/= Unb
.To_Unbounded_String
("ABCxxxDEABCDE") then
124 Report
.Failed
("Incorrect results from Replace_Slice - 4");
127 Unb
.Replace_Slice
(TC_Unb_String
, Low
=> 1, High
=> 0, By
=> "yyy");
129 if TC_Unb_String
/= Unb
.To_Unbounded_String
("yyyABCxxxDEABCDE") then
130 Report
.Failed
("Incorrect results from Replace_Slice - 5");
133 Unb
.Replace_Slice
(TC_Unb_String
,
134 Unb
.Length
(TC_Unb_String
) + 1,
135 Unb
.Length
(TC_Unb_String
),
138 if TC_Unb_String
/= Unb
.To_Unbounded_String
("yyyABCxxxDEABCDEzzz") then
139 Report
.Failed
("Incorrect results from Replace_Slice - 6");
145 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
147 begin -- Before not in Source'First..Source'Last + 1
148 Unb
.Insert
(Source
=> TC_Unb_String
,
149 Before
=> Unb
.Length
(TC_Unb_String
) + 2,
150 New_Item
=> TC_String_5
);
151 Report
.Failed
("Index_Error not raised by Insert when Before " &
152 "not in the range Source'First..Source'Last+1");
154 when Index_Error
=> null; -- OK, expected exception.
157 ("Unexpected exception raised by Insert when Before not in " &
158 "the range Source'First..Source'Last+1");
161 Unb
.Insert
(TC_Unb_String
, 1, "**");
163 if TC_Unb_String
/= Unb
.To_Unbounded_String
("**Test String") then
164 Report
.Failed
("Incorrect results from Insert - 1");
167 Unb
.Insert
(TC_Unb_String
, Unb
.Length
(TC_Unb_String
)+1, "**");
169 if TC_Unb_String
/= Unb
.To_Unbounded_String
("**Test String**") then
170 Report
.Failed
("Incorrect results from Insert - 2");
173 Unb
.Insert
(TC_Unb_String
, 8, "---");
175 if TC_Unb_String
/= Unb
.To_Unbounded_String
("**Test ---String**") then
176 Report
.Failed
("Incorrect results from Insert - 3");
179 Unb
.Insert
(TC_Unb_String
, 3, TC_Null_String
);
181 if TC_Unb_String
/= Unb
.To_Unbounded_String
("**Test ---String**") then
182 Report
.Failed
("Incorrect results from Insert - 4");
186 -- Procedure Overwrite
188 begin -- Position not in Source'First..Source'Last + 1
189 Unb
.Overwrite
(Source
=> TC_Unb_String
,
190 Position
=> Unb
.Length
(TC_Unb_String
) + 2,
191 New_Item
=> TC_String_5
);
192 Report
.Failed
("Index_Error not raised by Overwrite when Position " &
193 "not in the range Source'First..Source'Last+1");
195 when Index_Error
=> null; -- OK, expected exception.
198 ("Unexpected exception raised by Overwrite when Position not " &
199 "in the range Source'First..Source'Last+1");
202 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
204 Unb
.Overwrite
(Source
=> TC_Unb_String
,
208 if TC_Unb_String
/= Unb
.To_Unbounded_String
("XXXX String") then
209 Report
.Failed
("Incorrect results from Overwrite - 1");
212 Unb
.Overwrite
(TC_Unb_String
, Unb
.Length
(TC_Unb_String
)+1, "**");
214 if TC_Unb_String
/= Unb
.To_Unbounded_String
("XXXX String**") then
215 Report
.Failed
("Incorrect results from Overwrite - 2");
218 Unb
.Overwrite
(TC_Unb_String
, 3, TC_Null_String
);
220 if TC_Unb_String
/= Unb
.To_Unbounded_String
("XXXX String**") then
221 Report
.Failed
("Incorrect results from Overwrite - 3");
224 Unb
.Overwrite
(TC_Unb_String
, 1, "abcdefghijklmn");
226 if TC_Unb_String
/= Unb
.To_Unbounded_String
("abcdefghijklmn") then
227 Report
.Failed
("Incorrect results from Overwrite - 4");
233 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
235 -- From > Through (No change to Source)
237 Unb
.Delete
(Source
=> TC_Unb_String
,
238 From
=> Unb
.Length
(TC_Unb_String
),
239 Through
=> Unb
.Length
(TC_Unb_String
)-1);
241 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Test String") then
242 Report
.Failed
("Incorrect results from Delete - 1");
245 Unb
.Delete
(TC_Unb_String
, 1, 0);
247 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Test String") then
248 Report
.Failed
("Incorrect results from Delete - 2");
253 Unb
.Delete
(TC_Unb_String
, 1, 5);
255 if TC_Unb_String
/= Unb
.To_Unbounded_String
("String") then
256 Report
.Failed
("Incorrect results from Delete - 3");
259 Unb
.Delete
(TC_Unb_String
, 3, 3);
261 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Sting") then
262 Report
.Failed
("Incorrect results from Delete - 4");
268 TC_Unb_String
:= Unb
.To_Unbounded_String
("No Spaces");
270 Unb
.Trim
(Source
=> TC_Unb_String
, Side
=> Ada
.Strings
.Both
);
272 if TC_Unb_String
/= Unb
.To_Unbounded_String
("No Spaces") then
273 Report
.Failed
("Incorrect results from Trim - 1");
276 TC_Unb_String
:= Unb
.To_Unbounded_String
(" Leading Spaces ");
278 Unb
.Trim
(TC_Unb_String
, Ada
.Strings
.Left
);
280 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Leading Spaces ") then
281 Report
.Failed
("Incorrect results from Trim - 2");
284 TC_Unb_String
:= Unb
.To_Unbounded_String
(" Ending Spaces ");
286 Unb
.Trim
(TC_Unb_String
, Ada
.Strings
.Right
);
288 if TC_Unb_String
/= Unb
.To_Unbounded_String
(" Ending Spaces") then
289 Report
.Failed
("Incorrect results from Trim - 3");
293 Unb
.To_Unbounded_String
(" Spaces on both ends ");
295 Unb
.Trim
(TC_Unb_String
, Ada
.Strings
.Both
);
298 Unb
.To_Unbounded_String
("Spaces on both ends")
300 Report
.Failed
("Incorrect results from Trim - 4");
304 -- Procedure Trim (with Character Set parameters)
306 TC_Unb_String
:= Unb
.To_Unbounded_String
("lowerCASEletters");
308 Unb
.Trim
(Source
=> TC_Unb_String
,
309 Left
=> Ada
.Strings
.Maps
.Constants
.Lower_Set
,
310 Right
=> Ada
.Strings
.Maps
.Constants
.Lower_Set
);
312 if TC_Unb_String
/= Unb
.To_Unbounded_String
("CASE") then
313 Report
.Failed
("Incorrect results from Trim with Sets - 1");
316 TC_Unb_String
:= Unb
.To_Unbounded_String
("lowerCASEletters");
318 Unb
.Trim
(TC_Unb_String
,
319 Ada
.Strings
.Maps
.Constants
.Upper_Set
,
320 Ada
.Strings
.Maps
.Constants
.Upper_Set
);
322 if TC_Unb_String
/= Unb
.To_Unbounded_String
("lowerCASEletters") then
323 Report
.Failed
("Incorrect results from Trim with Sets - 2");
326 TC_Unb_String
:= Unb
.To_Unbounded_String
("012abcdefghGFEDCBA789ab");
328 Unb
.Trim
(TC_Unb_String
,
329 Ada
.Strings
.Maps
.Constants
.Hexadecimal_Digit_Set
,
330 Ada
.Strings
.Maps
.Constants
.Hexadecimal_Digit_Set
);
332 if TC_Unb_String
/= Unb
.To_Unbounded_String
("ghG") then
333 Report
.Failed
("Incorrect results from Trim with Sets - 3");
339 -- Count <= Source'Length
341 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
343 Unb
.Head
(Source
=> TC_Unb_String
,
347 if TC_Unb_String
/= Unb
.Null_Unbounded_String
then
348 Report
.Failed
("Incorrect results from Head - 1");
351 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
353 Unb
.Head
(Source
=> TC_Unb_String
,
357 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Test") then
358 Report
.Failed
("Incorrect results from Head - 2");
361 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
363 Unb
.Head
(Source
=> TC_Unb_String
,
364 Count
=> Unb
.Length
(TC_Unb_String
),
367 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Test String") then
368 Report
.Failed
("Incorrect results from Head - 3");
371 -- Count > Source'Length
373 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
375 Unb
.Head
(Source
=> TC_Unb_String
,
376 Count
=> Unb
.Length
(TC_Unb_String
) + 4,
379 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Test String****") then
380 Report
.Failed
("Incorrect results from Head - 4");
383 TC_Unb_String
:= Unb
.Null_Unbounded_String
;
385 Unb
.Head
(Source
=> TC_Unb_String
,
386 Count
=> Unb
.Length
(TC_Unb_String
) + 3,
389 if TC_Unb_String
/= Unb
.To_Unbounded_String
("***") then
390 Report
.Failed
("Incorrect results from Head - 5");
396 -- Count <= Source'Length
398 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
400 Unb
.Tail
(Source
=> TC_Unb_String
,
404 if TC_Unb_String
/= Unb
.Null_Unbounded_String
then
405 Report
.Failed
("Incorrect results from Tail - 1");
408 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
410 Unb
.Tail
(Source
=> TC_Unb_String
,
414 if TC_Unb_String
/= Unb
.To_Unbounded_String
("String") then
415 Report
.Failed
("Incorrect results from Tail - 2");
418 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
420 Unb
.Tail
(Source
=> TC_Unb_String
,
421 Count
=> Unb
.Length
(TC_Unb_String
),
424 if TC_Unb_String
/= Unb
.To_Unbounded_String
("Test String") then
425 Report
.Failed
("Incorrect results from Tail - 3");
428 -- Count > Source'Length
430 TC_Unb_String
:= Unb
.To_Unbounded_String
("Test String");
432 Unb
.Tail
(Source
=> TC_Unb_String
,
433 Count
=> Unb
.Length
(TC_Unb_String
) + 5,
436 if TC_Unb_String
/= Unb
.To_Unbounded_String
("xxxxxTest String") then
437 Report
.Failed
("Incorrect results from Tail - 4");
440 TC_Unb_String
:= Unb
.Null_Unbounded_String
;
442 Unb
.Tail
(Source
=> TC_Unb_String
,
443 Count
=> Unb
.Length
(TC_Unb_String
) + 3,
446 if TC_Unb_String
/= Unb
.To_Unbounded_String
("XXX") then
447 Report
.Failed
("Incorrect results from Tail - 5");
452 when others => Report
.Failed
("Exception raised in Test_Block");