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 the subprograms defined in package Ada.Strings.Unbounded
28 -- are available, and that they produce correct results. Specifically,
29 -- check the subprograms To_Unbounded_String, "&", ">", "<", Element,
30 -- Replace_Element, Count, Find_Token, Translate, Trim, Delete, and
34 -- This test demonstrates the uses of many of the subprograms defined
35 -- in package Ada.Strings.Unbounded for use with unbounded strings.
36 -- The test simulates how unbounded strings could be processed in a
37 -- user environment, using the subprograms provided in this package.
39 -- This test uses a variety of the subprograms defined in the unbounded
40 -- string package in ways typical of common usage, with different
41 -- combinations of available subprograms being used to accomplish
42 -- similar unbounded string processing goals.
46 -- 06 Dec 94 SAIC ACVC 2.0
47 -- 27 Feb 95 SAIC Test description modification.
48 -- 01 Nov 95 SAIC Update and repair for ACVC 2.0.1.
53 with Ada
.Strings
.Maps
;
54 with Ada
.Strings
.Unbounded
;
59 Report
.Test
("CXA4011", "Check that the subprograms defined in " &
60 "package Ada.Strings.Unbounded are available, " &
61 "and that they produce correct results");
66 package ASUnb
renames Ada
.Strings
.Unbounded
;
68 use type Maps
.Character_Set
;
69 use type ASUnb
.Unbounded_String
;
71 Cad_String
: ASUnb
.Unbounded_String
:=
72 ASUnb
.To_Unbounded_String
("cad");
74 Complete_String
: ASUnb
.Unbounded_String
:=
75 ASUnb
.To_Unbounded_String
("Incomplete") &
77 ASUnb
.To_Unbounded_String
("String");
79 Incomplete_String
: ASUnb
.Unbounded_String
:=
80 ASUnb
.To_Unbounded_String
("ncomplete Strin");
82 Incorrect_Spelling
: ASUnb
.Unbounded_String
:=
83 ASUnb
.To_Unbounded_String
("Guob Dai");
85 Magic_String
: ASUnb
.Unbounded_String
:=
86 ASUnb
.To_Unbounded_String
("abracadabra");
88 Incantation
: ASUnb
.Unbounded_String
:= Magic_String
;
91 A_Small_G
: Character := 'g';
92 A_Small_D
: Character := 'd';
94 ABCD_Set
: Maps
.Character_Set
:= Maps
.To_Set
("abcd");
95 B_Set
: Maps
.Character_Set
:= Maps
.To_Set
('b');
96 AB_Set
: Maps
.Character_Set
:= Maps
."OR"(Maps
.To_Set
('a'), B_Set
);
98 Code_Map
: Maps
.Character_Mapping
:=
99 Maps
.To_Mapping
(From
=> "abcd", To
=> "wxyz");
100 Reverse_Code_Map
: Maps
.Character_Mapping
:=
101 Maps
.To_Mapping
(From
=> "wxyz", To
=> "abcd");
102 Non_Existent_Map
: Maps
.Character_Mapping
:=
103 Maps
.To_Mapping
(From
=> "jkl", To
=> "mno");
106 Token_Start
: Positive;
107 Token_End
: Natural := 0;
108 Matching_Letters
: Natural := 0;
115 -- Prepend an 'I' and append a 'g' to the string.
116 Incomplete_String
:= ASUnb
."&"('I', Incomplete_String
); -- Char & Unb
117 Incomplete_String
:= ASUnb
."&"(Incomplete_String
,
118 A_Small_G
); -- Unb & Char
120 if Incomplete_String
< Complete_String
or
121 Incomplete_String
> Complete_String
or
122 Incomplete_String
/= Complete_String
124 Report
.Failed
("Incorrect result from use of ""&"" operator");
130 -- Last element of the unbounded string should be a 'g'.
131 if ASUnb
.Element
(Incomplete_String
, ASUnb
.Length
(Incomplete_String
)) /=
134 Report
.Failed
("Incorrect result from use of Function Element - 1");
137 if ASUnb
.Element
(Incomplete_String
, 2) /=
138 ASUnb
.Element
(ASUnb
.Tail
(Incomplete_String
, 2), 1) or
139 ASUnb
.Element
(ASUnb
.Head
(Incomplete_String
, 4), 2) /=
140 ASUnb
.Element
(ASUnb
.To_Unbounded_String
("wnqz"), 2)
142 Report
.Failed
("Incorrect result from use of Function Element - 2");
148 -- The unbounded string Incorrect_Spelling starts as "Guob Dai", and
149 -- is transformed by the following three procedure calls to "Good Day".
151 ASUnb
.Replace_Element
(Incorrect_Spelling
, 2, 'o');
153 ASUnb
.Replace_Element
(Incorrect_Spelling
,
154 ASUnb
.Index
(Incorrect_Spelling
, B_Set
),
157 ASUnb
.Replace_Element
(Source
=> Incorrect_Spelling
,
158 Index
=> ASUnb
.Length
(Incorrect_Spelling
),
161 if Incorrect_Spelling
/= ASUnb
.To_Unbounded_String
("Good Day") then
162 Report
.Failed
("Incorrect result from Procedure Replace_Element");
168 -- Determine the number of characters in the unbounded string that
169 -- are contained in the set.
171 Matching_Letters
:= ASUnb
.Count
(Source
=> Magic_String
,
174 if Matching_Letters
/= 9 then
176 ("Incorrect result from Function Count with Set parameter");
179 -- Determine the number of occurrences of the following pattern strings
180 -- in the unbounded string Magic_String.
182 if ASUnb
.Count
(Magic_String
, "ab") /=
183 (ASUnb
.Count
(Magic_String
, "ac") + ASUnb
.Count
(Magic_String
, "ad")) or
184 ASUnb
.Count
(Magic_String
, "ab") /= 2
187 ("Incorrect result from Function Count with String parameter");
193 ASUnb
.Find_Token
(Magic_String
, -- Find location of first "ab".
194 AB_Set
, -- Should be (1..2).
199 if Natural(Token_Start
) /= ASUnb
.To_String
(Magic_String
)'First or
200 Token_End
/= ASUnb
.Index
(Magic_String
, B_Set
)
202 Report
.Failed
("Incorrect result from Procedure Find_Token - 1");
206 ASUnb
.Find_Token
(Source
=> Magic_String
, -- Find location of char 'r'
207 Set
=> ABCD_Set
, -- in string, should be (3..3)
208 Test
=> Ada
.Strings
.Outside
,
209 First
=> Token_Start
,
212 if Natural(Token_Start
) /= 3 or
214 Report
.Failed
("Incorrect result from Procedure Find_Token - 2");
218 ASUnb
.Find_Token
(Magic_String
, -- No 'g' is in the string, so
219 Maps
.To_Set
(A_Small_G
), -- the result parameters should
220 Ada
.Strings
.Inside
, -- be First = Source'First and
221 First
=> Token_Start
, -- Last = 0.
224 if Token_Start
/= ASUnb
.To_String
(Magic_String
)'First or
227 Report
.Failed
("Incorrect result from Procedure Find_Token - 3");
233 -- Use a mapping ("abcd" -> "wxyz") to transform the contents of
234 -- the unbounded string.
235 -- Magic_String = "abracadabra"
237 Incantation
:= ASUnb
.Translate
(Magic_String
, Code_Map
);
239 if Incantation
/= ASUnb
.To_Unbounded_String
("wxrwywzwxrw") then
240 Report
.Failed
("Incorrect result from Function Translate");
243 -- Use the inverse mapping of the one above to return the "translated"
244 -- unbounded string to its original form.
246 ASUnb
.Translate
(Incantation
, Reverse_Code_Map
);
248 -- The map contained in the following call to Translate contains one
249 -- element, and this element is not found in the unbounded string, so
250 -- this call to Translate should have no effect on the unbounded string.
252 if Incantation
/= ASUnb
.Translate
(Magic_String
, Non_Existent_Map
) then
253 Report
.Failed
("Incorrect result from Procedure Translate");
262 XYZ_Set
: Maps
.Character_Set
:= Maps
.To_Set
("xyz");
263 PQR_Set
: Maps
.Character_Set
:= Maps
.To_Set
("pqr");
265 Pad
: constant ASUnb
.Unbounded_String
:=
266 ASUnb
.To_Unbounded_String
("Pad");
268 The_New_Ada
: constant ASUnb
.Unbounded_String
:=
269 ASUnb
.To_Unbounded_String
("Ada9X");
271 Space_Array
: array (1..4) of ASUnb
.Unbounded_String
:=
272 (ASUnb
.To_Unbounded_String
(" Pad "),
273 ASUnb
.To_Unbounded_String
("Pad "),
274 ASUnb
.To_Unbounded_String
(" Pad"),
277 String_Array
: array (1..5) of ASUnb
.Unbounded_String
:=
278 (ASUnb
.To_Unbounded_String
("xyzxAda9Xpqr"),
279 ASUnb
.To_Unbounded_String
("Ada9Xqqrp"),
280 ASUnb
.To_Unbounded_String
("zxyxAda9Xqpqr"),
281 ASUnb
.To_Unbounded_String
("xxxyAda9X"),
286 -- Examine the version of Trim that removes blanks from
287 -- the left and/or right of a string.
290 if ASUnb
.Trim
(Space_Array
(i
), Ada
.Strings
.Both
) /= Pad
then
291 Report
.Failed
("Incorrect result from Trim for spaces - " &
296 -- Examine the version of Trim that removes set characters from
297 -- the left and right of a string.
300 if ASUnb
.Trim
(String_Array
(i
),
302 Right
=> PQR_Set
) /= The_New_Ada
then
304 ("Incorrect result from Trim for set characters - " &
314 -- Use the Delete function to remove the first four and last four
315 -- characters from the string.
317 if ASUnb
.Delete
(Source
=> ASUnb
.Delete
(Magic_String
,
319 ASUnb
.Length
(Magic_String
)),
320 From
=> ASUnb
.To_String
(Magic_String
)'First,
324 Report
.Failed
("Incorrect results from Function Delete");
328 -- Constructors ("*")
333 SOS
: ASUnb
.Unbounded_String
;
335 Dot
: constant ASUnb
.Unbounded_String
:=
336 ASUnb
.To_Unbounded_String
("Dot_");
337 Dash
: constant String := "Dash_";
339 Distress
: ASUnb
.Unbounded_String
:=
340 ASUnb
.To_Unbounded_String
("Dot_Dot_Dot_") &
341 ASUnb
.To_Unbounded_String
("Dash_Dash_Dash_") &
342 ASUnb
.To_Unbounded_String
("Dot_Dot_Dot");
344 Repeat
: constant Natural := 3;
345 Separator
: constant Character := '_';
347 Separator_Set
: Maps
.Character_Set
:= Maps
.To_Set
(Separator
);
351 -- Use the following constructor forms to construct the string
352 -- "Dot_Dot_Dot_Dash_Dash_Dash_Dot_Dot_Dot". Note that the
353 -- trailing underscore in the string is removed in the call to
354 -- Trim in the If statement condition.
356 SOS
:= ASUnb
."*"(Repeat
, Dot
); -- "*"(#, Unb Str)
359 ASUnb
."*"(Repeat
, Dash
) & -- "*"(#, Str)
360 ASUnb
."*"(Repeat
, Dot
); -- "*"(#, Unb Str)
362 if ASUnb
.Trim
(SOS
, Maps
.Null_Set
, Separator_Set
) /= Distress
then
363 Report
.Failed
("Incorrect results from Function ""*""");
366 end Constructor_Block
;
370 when others => Report
.Failed
("Exception raised in Test_Block");