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.Fixed are
28 -- available, and that they produce correct results. Specifically, check
29 -- the subprograms Count, Find_Token, Index, Index_Non_Blank, and Move.
32 -- This test, when combined with tests CXA4002,3, and 5 will provide
33 -- thorough coverage of the functionality found in Ada.Strings.Fixed.
34 -- This test contains many small, specific test cases, situations that
35 -- although common in user environments, are often difficult to generate
36 -- in large numbers in a application-based test.
40 -- 06 Dec 94 SAIC ACVC 2.0
41 -- 10 Apr 95 SAIC Corrected subtest for Move, Drop=Right.
47 with Ada
.Strings
.Fixed
;
48 with Ada
.Strings
.Maps
;
53 Report
.Test
("CXA4004", "Check that the subprograms defined in " &
54 "package Ada.Strings.Fixed are available, " &
55 "and that they produce correct results");
60 package ASF
renames Ada
.Strings
.Fixed
;
61 package Maps
renames Ada
.Strings
.Maps
;
63 Result_String
: String(1..10) := (others => Ada
.Strings
.Space
);
65 Source_String1
: String(1..5) := "abcde"; -- odd length string
66 Source_String2
: String(1..6) := "abcdef"; -- even length string
67 Source_String3
: String(1..12) := "abcdefghijkl";
68 Source_String4
: String(1..12) := "abcdefghij "; -- last two ch pad
69 Source_String5
: String(1..12) := " cdefghijkl"; -- first two ch pad
70 Source_String6
: String(1..12) := "abcdefabcdef";
72 Location
: Natural := 0;
73 Slice_Start
: Positive;
75 Slice_Count
: Natural := 0;
77 CD_Set
: Maps
.Character_Set
:= Maps
.To_Set
("cd");
78 ABCD_Set
: Maps
.Character_Set
:= Maps
.To_Set
("abcd");
79 A_to_F_Set
: Maps
.Character_Set
:= Maps
.To_Set
("abcdef");
81 CD_to_XY_Map
: Maps
.Character_Mapping
:=
82 Maps
.To_Mapping
(From
=> "cd", To
=> "xy");
88 -- Evaluate the Procedure Move with various combinations of
91 -- Justify = Left (default case)
93 ASF
.Move
(Source
=> Source_String1
, -- "abcde"
94 Target
=> Result_String
);
96 if Result_String
/= "abcde " then
97 Report
.Failed
("Incorrect result from Move with Justify = Left");
102 ASF
.Move
(Source
=> Source_String2
, -- "abcdef"
103 Target
=> Result_String
,
104 Drop
=> Ada
.Strings
.Error
,
105 Justify
=> Ada
.Strings
.Right
);
107 if Result_String
/= " abcdef" then
108 Report
.Failed
("Incorrect result from Move with Justify = Right");
111 -- Justify = Center (two cases, odd and even pad lengths)
113 ASF
.Move
(Source_String1
, -- "abcde"
117 'x'); -- non-default padding.
119 if Result_String
/= "xxabcdexxx" then -- Unequal padding added right
120 Report
.Failed
("Incorrect result from Move with Justify = Center-1");
123 ASF
.Move
(Source_String2
, -- "abcdef"
128 if Result_String
/= " abcdef " then -- Equal padding added on L/R.
129 Report
.Failed
("Incorrect result from Move with Justify = Center-2");
132 -- When the source string is longer than the target string, several
133 -- cases can be examined, with the results depending on the value of
134 -- the Drop parameter.
138 ASF
.Move
(Source
=> Source_String3
, -- "abcdefghijkl"
139 Target
=> Result_String
,
140 Drop
=> Ada
.Strings
.Left
);
142 if Result_String
/= "cdefghijkl" then
143 Report
.Failed
("Incorrect result from Move with Drop = Left");
148 ASF
.Move
(Source_String3
, Result_String
, Ada
.Strings
.Right
);
150 if Result_String
/= "abcdefghij" then
151 Report
.Failed
("Incorrect result from Move with Drop = Right");
155 -- The effect in this case depends on the value of the justify
156 -- parameter, and on whether any characters in Source other than
157 -- Pad would fail to be copied.
159 -- Drop = Error, Justify = Left, right overflow characters are pad.
161 ASF
.Move
(Source
=> Source_String4
, -- "abcdefghij "
162 Target
=> Result_String
,
163 Drop
=> Ada
.Strings
.Error
,
164 Justify
=> Ada
.Strings
.Left
);
166 if not(Result_String
= "abcdefghij") then -- leftmost 10 characters
167 Report
.Failed
("Incorrect result from Move with Drop = Error - 1");
170 -- Drop = Error, Justify = Right, left overflow characters are pad.
172 ASF
.Move
(Source_String5
, -- " cdefghijkl"
177 if Result_String
/= "cdefghijkl" then -- rightmost 10 characters
178 Report
.Failed
("Incorrect result from Move with Drop = Error - 2");
181 -- In other cases of Drop=Error, Length_Error is propagated, such as:
185 ASF
.Move
(Source_String3
, -- 12 characters, no Pad.
186 Result_String
, -- 10 characters
190 Report
.Failed
("Length_Error not raised by Move - 1");
193 when Ada
.Strings
.Length_Error
=> null; -- OK
195 Report
.Failed
("Incorrect exception raised by Move - 1");
201 -- (Other usage examples of this function found in CXA4002-3.)
202 -- Check when the pattern is not found in the source.
204 if ASF
.Index
("abcdef", "gh") /= 0 or
205 ASF
.Index
("abcde", "abcdef") /= 0 or -- pattern > source
208 Ada
.Strings
.Backward
) /= 0 or
209 ASF
.Index
("", "ab") /= 0 or -- null source string.
210 ASF
.Index
("abcde", " ") /= 0 -- blank pattern.
212 Report
.Failed
("Incorrect result from Index, no pattern match");
215 -- Check that Pattern_Error is raised when the pattern is the
218 Location
:= ASF
.Index
(Source_String6
, -- "abcdefabcdef"
219 "", -- null pattern string.
220 Ada
.Strings
.Forward
);
221 Report
.Failed
("Pattern_Error not raised by Index");
223 when Ada
.Strings
.Pattern_Error
=> null; -- OK, expected exception.
225 Report
.Failed
("Incorrect exception raised by Index, null pattern");
228 -- Use the search direction "backward" to locate the particular
229 -- pattern within the source string.
231 Location
:= ASF
.Index
(Source_String6
, -- "abcdefabcdef"
232 "de", -- slice 4..5, 10..11
233 Ada
.Strings
.Backward
); -- search from right end.
235 if Location
/= 10 then
236 Report
.Failed
("Incorrect result from Index going Backward");
239 -- Using the version of Index testing character set membership,
240 -- check combinations of forward/backward, inside/outside parameter
243 if ASF
.Index
(Source
=> Source_String1
, -- "abcde"
245 Test
=> Ada
.Strings
.Inside
,
246 Going
=> Ada
.Strings
.Forward
) /= 3 or -- 'c' at pos 3.
247 ASF
.Index
(Source_String6
, -- "abcdefabcdef"
250 Ada
.Strings
.Backward
) /= 12 or -- 'f' at position 12
251 ASF
.Index
(Source_String6
, -- "abcdefabcdef"
254 Ada
.Strings
.Backward
) /= 10 or -- 'd' at position 10
255 ASF
.Index
("cdcdcdcdacdcdcdcd",
258 Ada
.Strings
.Forward
) /= 9 -- 'a' at position 9
260 Report
.Failed
("Incorrect result from function Index for sets - 1");
263 -- Additional interesting uses/combinations using Index for sets.
265 if ASF
.Index
("cd", -- same size, str-set
268 Ada
.Strings
.Forward
) /= 1 or -- 'c' at position 1
269 ASF
.Index
("abcd", -- same size, str-set,
270 Maps
.To_Set
("efgh"), -- different contents.
272 Ada
.Strings
.Forward
) /= 1 or
273 ASF
.Index
("abccd", -- set > string
274 Maps
.To_Set
("acegik"),
276 Ada
.Strings
.Backward
) /= 4 or -- 'c' at position 4
278 Maps
.Null_Set
) /= 0 or
279 ASF
.Index
("", -- Null string.
281 ASF
.Index
("abc ab", -- blank included
282 Maps
.To_Set
("e "), -- in string and set.
284 Ada
.Strings
.Backward
) /= 4 -- blank in string.
286 Report
.Failed
("Incorrect result from function Index for sets - 2");
291 -- Function Index_Non_Blank.
292 -- (Other usage examples of this function found in CXA4002-3.)
295 if ASF
.Index_Non_Blank
(Source
=> Source_String4
, -- "abcdefghij "
296 Going
=> Ada
.Strings
.Backward
) /= 10 or
297 ASF
.Index_Non_Blank
("abc def ghi jkl ",
298 Ada
.Strings
.Backward
) /= 15 or
299 ASF
.Index_Non_Blank
(" abcdef") /= 3 or
300 ASF
.Index_Non_Blank
(" ") /= 0
302 Report
.Failed
("Incorrect result from Index_Non_Blank");
308 -- (Other usage examples of this function found in CXA4002-3.)
310 if ASF
.Count
("abababa", "aba") /= 2 or
311 ASF
.Count
("abababa", "ab" ) /= 3 or
312 ASF
.Count
("babababa", "ab") /= 3 or
313 ASF
.Count
("abaabaaba", "aba") /= 3 or
314 ASF
.Count
("xxxxxxxxxxxxxxxxxxxy", "xy") /= 1 or
315 ASF
.Count
("xxxxxxxxxxxxxxxxxxxx", "x") /= 20
317 Report
.Failed
("Incorrect result from Function Count");
320 -- Determine the number of slices of Source that when mapped to a
321 -- non-identity map, match the pattern string.
323 Slice_Count
:= ASF
.Count
(Source_String6
, -- "abcdefabcdef"
325 CD_to_XY_Map
); -- maps 'c' to 'x', 'd' to 'y'
327 if Slice_Count
/= 2 then -- two slices "xy" in "mapped" Source_String6
328 Report
.Failed
("Incorrect result from Count with non-identity map");
331 -- If the pattern supplied to Function Count is the null string, then
332 -- Pattern_Error is propagated.
335 The_Null_String
: constant String := "";
337 Slice_Count
:= ASF
.Count
(Source_String6
, The_Null_String
);
338 Report
.Failed
("Pattern_Error not raised by Function Count");
340 when Ada
.Strings
.Pattern_Error
=> null; -- OK
342 Report
.Failed
("Incorrect exception from Count with null pattern");
346 -- Function Count returning the number of characters in a particular
347 -- set that are found in source string.
349 if ASF
.Count
(Source_String6
, CD_Set
) /= 4 then -- 2 'c' and 'd' chars.
350 Report
.Failed
("Incorrect result from Count with set");
355 -- Function Find_Token.
356 -- (Other usage examples of this function found in CXA4002-3.)
358 ASF
.Find_Token
(Source
=> Source_String6
, -- First slice with no
359 Set
=> ABCD_Set
, -- 'a', 'b', 'c', or 'd'
360 Test
=> Ada
.Strings
.Outside
, -- is "ef" at 5..6.
361 First
=> Slice_Start
,
364 if Slice_Start
/= 5 or Slice_End
/= 6 then
365 Report
.Failed
("Incorrect result from Find_Token - 1");
368 -- If no appropriate slice is contained by the source string, then the
369 -- value returned in Last is zero, and the value in First is
372 ASF
.Find_Token
(Source_String6
, -- "abcdefabcdef"
373 A_to_F_Set
, -- Set of characters 'a' thru 'f'.
374 Ada
.Strings
.Outside
, -- No characters outside this set.
378 if Slice_Start
/= Source_String6
'First or Slice_End
/= 0 then
379 Report
.Failed
("Incorrect result from Find_Token - 2");
382 -- Additional testing of Find_Token.
384 ASF
.Find_Token
("eabcdabcddcab",
390 if Slice_Start
/= 2 or Slice_End
/= 13 then
391 Report
.Failed
("Incorrect result from Find_Token - 3");
394 ASF
.Find_Token
("efghijklabcdabcd",
400 if Slice_Start
/= 1 or Slice_End
/= 8 then
401 Report
.Failed
("Incorrect result from Find_Token - 4");
404 ASF
.Find_Token
("abcdefgabcdabcd",
410 if Slice_Start
/= 5 or Slice_End
/= 7 then
411 Report
.Failed
("Incorrect result from Find_Token - 5");
414 ASF
.Find_Token
("abcdcbabcdcba",
420 if Slice_Start
/= 1 or Slice_End
/= 13 then
421 Report
.Failed
("Incorrect result from Find_Token - 6");
426 when others => Report
.Failed
("Exception raised in Test_Block");