-- CXA4008.A
|
-- CXA4008.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
-- unlimited rights in the software and documentation contained herein.
|
-- unlimited rights in the software and documentation contained herein.
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- this public release, the Government intends to confer upon all
|
-- this public release, the Government intends to confer upon all
|
-- recipients unlimited rights equal to those held by the Government.
|
-- recipients unlimited rights equal to those held by the Government.
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- released technical data and computer software in whole or in part, in
|
-- released technical data and computer software in whole or in part, in
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- to do so.
|
-- to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that the subprograms defined in package Ada.Strings.Bounded are
|
-- Check that the subprograms defined in package Ada.Strings.Bounded are
|
-- available, and that they produce correct results, especially under
|
-- available, and that they produce correct results, especially under
|
-- conditions where truncation of the result is required. Specifically,
|
-- conditions where truncation of the result is required. Specifically,
|
-- check the subprograms Append, Count with non-Identity maps, Index with
|
-- check the subprograms Append, Count with non-Identity maps, Index with
|
-- non-Identity maps, Index with Set parameters, Insert (function and
|
-- non-Identity maps, Index with Set parameters, Insert (function and
|
-- procedure), Replace_Slice (function and procedure), To_Bounded_String,
|
-- procedure), Replace_Slice (function and procedure), To_Bounded_String,
|
-- and Translate.
|
-- and Translate.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- This test, in conjunction with tests CXA4006, CXA4007, and CXA4009,
|
-- This test, in conjunction with tests CXA4006, CXA4007, and CXA4009,
|
-- will provide coverage of the most common usages of the functionality
|
-- will provide coverage of the most common usages of the functionality
|
-- found in the Ada.Strings.Bounded package. It deals in large part
|
-- found in the Ada.Strings.Bounded package. It deals in large part
|
-- with truncation effects and options. This test contains many small,
|
-- with truncation effects and options. This test contains many small,
|
-- specific test cases, situations that are often difficult to generate
|
-- specific test cases, situations that are often difficult to generate
|
-- in large numbers in an application-based test. These cases represent
|
-- in large numbers in an application-based test. These cases represent
|
-- specific usage paradigms in-the-small.
|
-- specific usage paradigms in-the-small.
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 10 Apr 95 SAIC Corrected acceptance condition of subtest for
|
-- 10 Apr 95 SAIC Corrected acceptance condition of subtest for
|
-- Function Append with Truncation = Left.
|
-- Function Append with Truncation = Left.
|
-- 31 Oct 95 SAIC Update and repair for ACVC 2.0.1.
|
-- 31 Oct 95 SAIC Update and repair for ACVC 2.0.1.
|
--
|
--
|
--!
|
--!
|
|
|
with Report;
|
with Report;
|
with Ada.Strings.Maps.Constants;
|
with Ada.Strings.Maps.Constants;
|
with Ada.Strings.Bounded;
|
with Ada.Strings.Bounded;
|
with Ada.Strings.Maps;
|
with Ada.Strings.Maps;
|
|
|
procedure CXA4008 is
|
procedure CXA4008 is
|
|
|
begin
|
begin
|
|
|
Report.Test("CXA4008", "Check that the subprograms defined in " &
|
Report.Test("CXA4008", "Check that the subprograms defined in " &
|
"package Ada.Strings.Bounded are available, " &
|
"package Ada.Strings.Bounded are available, " &
|
"and that they produce correct results, " &
|
"and that they produce correct results, " &
|
"especially under conditions where " &
|
"especially under conditions where " &
|
"truncation of the result is required");
|
"truncation of the result is required");
|
|
|
Test_Block:
|
Test_Block:
|
declare
|
declare
|
|
|
package AS renames Ada.Strings;
|
package AS renames Ada.Strings;
|
package ASB renames Ada.Strings.Bounded;
|
package ASB renames Ada.Strings.Bounded;
|
package ASC renames Ada.Strings.Maps.Constants;
|
package ASC renames Ada.Strings.Maps.Constants;
|
package Maps renames Ada.Strings.Maps;
|
package Maps renames Ada.Strings.Maps;
|
|
|
package B10 is new ASB.Generic_Bounded_Length(Max => 10);
|
package B10 is new ASB.Generic_Bounded_Length(Max => 10);
|
use type B10.Bounded_String;
|
use type B10.Bounded_String;
|
|
|
Result_String : B10.Bounded_String;
|
Result_String : B10.Bounded_String;
|
Test_String : B10.Bounded_String;
|
Test_String : B10.Bounded_String;
|
AtoE_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("abcde");
|
AtoE_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("abcde");
|
FtoJ_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("fghij");
|
FtoJ_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("fghij");
|
AtoJ_Bnd_Str : B10.Bounded_String :=
|
AtoJ_Bnd_Str : B10.Bounded_String :=
|
B10.To_Bounded_String("abcdefghij");
|
B10.To_Bounded_String("abcdefghij");
|
|
|
Location : Natural := 0;
|
Location : Natural := 0;
|
Total_Count : Natural := 0;
|
Total_Count : Natural := 0;
|
|
|
CD_Set : Maps.Character_Set := Maps.To_Set("cd");
|
CD_Set : Maps.Character_Set := Maps.To_Set("cd");
|
|
|
AB_to_YZ_Map : Maps.Character_Mapping :=
|
AB_to_YZ_Map : Maps.Character_Mapping :=
|
Maps.To_Mapping(From => "ab", To => "yz");
|
Maps.To_Mapping(From => "ab", To => "yz");
|
|
|
CD_to_XY_Map : Maps.Character_Mapping :=
|
CD_to_XY_Map : Maps.Character_Mapping :=
|
Maps.To_Mapping(From => "cd", To => "xy");
|
Maps.To_Mapping(From => "cd", To => "xy");
|
|
|
|
|
begin
|
begin
|
-- Function To_Bounded_String with Truncation
|
-- Function To_Bounded_String with Truncation
|
-- Evaluate the function Append with parameters that will
|
-- Evaluate the function Append with parameters that will
|
-- cause the truncation of the result.
|
-- cause the truncation of the result.
|
|
|
-- Drop = Error (default case, Length_Error will be raised)
|
-- Drop = Error (default case, Length_Error will be raised)
|
|
|
begin
|
begin
|
Test_String :=
|
Test_String :=
|
B10.To_Bounded_String("Much too long for this bounded string");
|
B10.To_Bounded_String("Much too long for this bounded string");
|
Report.Failed("Length Error not raised by To_Bounded_String");
|
Report.Failed("Length Error not raised by To_Bounded_String");
|
exception
|
exception
|
when AS.Length_Error => null; -- Expected exception raised.
|
when AS.Length_Error => null; -- Expected exception raised.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by To_Bounded_String");
|
Report.Failed("Incorrect exception raised by To_Bounded_String");
|
end;
|
end;
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn",
|
Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn",
|
Drop => Ada.Strings.Left);
|
Drop => Ada.Strings.Left);
|
|
|
if Test_String /= B10.To_Bounded_String("efghijklmn") then
|
if Test_String /= B10.To_Bounded_String("efghijklmn") then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from To_Bounded_String, Drop = Left");
|
("Incorrect result from To_Bounded_String, Drop = Left");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn",
|
Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn",
|
Drop => Ada.Strings.Right);
|
Drop => Ada.Strings.Right);
|
|
|
if not(Test_String = AtoJ_Bnd_Str) then
|
if not(Test_String = AtoJ_Bnd_Str) then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from To_Bounded_String, Drop = Right");
|
("Incorrect result from To_Bounded_String, Drop = Right");
|
end if;
|
end if;
|
|
|
|
|
|
|
|
|
-- Function Append with Truncation
|
-- Function Append with Truncation
|
-- Evaluate the function Append with parameters that will
|
-- Evaluate the function Append with parameters that will
|
-- cause the truncation of the result.
|
-- cause the truncation of the result.
|
|
|
-- Drop = Error (default case, Length_Error will be raised)
|
-- Drop = Error (default case, Length_Error will be raised)
|
|
|
begin
|
begin
|
-- Append (Bnd Str, Bnd Str);
|
-- Append (Bnd Str, Bnd Str);
|
Result_String :=
|
Result_String :=
|
B10.Append(B10.To_Bounded_String("abcde"),
|
B10.Append(B10.To_Bounded_String("abcde"),
|
B10.To_Bounded_String("fghijk")); -- 11 char
|
B10.To_Bounded_String("fghijk")); -- 11 char
|
Report.Failed("Length_Error not raised by Append - 1");
|
Report.Failed("Length_Error not raised by Append - 1");
|
exception
|
exception
|
when AS.Length_Error => null; -- OK, correct exception raised.
|
when AS.Length_Error => null; -- OK, correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Append - 1");
|
Report.Failed("Incorrect exception raised by Append - 1");
|
end;
|
end;
|
|
|
begin
|
begin
|
-- Append (Str, Bnd Str);
|
-- Append (Str, Bnd Str);
|
Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str),
|
Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str),
|
B10.To_Bounded_String("fghijk"),
|
B10.To_Bounded_String("fghijk"),
|
AS.Error);
|
AS.Error);
|
Report.Failed("Length_Error not raised by Append - 2");
|
Report.Failed("Length_Error not raised by Append - 2");
|
exception
|
exception
|
when AS.Length_Error => null; -- OK, correct exception raised.
|
when AS.Length_Error => null; -- OK, correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Append - 2");
|
Report.Failed("Incorrect exception raised by Append - 2");
|
end;
|
end;
|
|
|
begin
|
begin
|
-- Append (Bnd Str, Char);
|
-- Append (Bnd Str, Char);
|
Result_String :=
|
Result_String :=
|
B10.Append(B10.To_Bounded_String("abcdefghij"), 'k');
|
B10.Append(B10.To_Bounded_String("abcdefghij"), 'k');
|
Report.Failed("Length_Error not raised by Append - 3");
|
Report.Failed("Length_Error not raised by Append - 3");
|
exception
|
exception
|
when AS.Length_Error => null; -- OK, correct exception raised.
|
when AS.Length_Error => null; -- OK, correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Append - 3");
|
Report.Failed("Incorrect exception raised by Append - 3");
|
end;
|
end;
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
-- Append (Bnd Str, Bnd Str)
|
-- Append (Bnd Str, Bnd Str)
|
Result_String := B10.Append(B10.To_Bounded_String("abcdefgh"), -- 8 chs
|
Result_String := B10.Append(B10.To_Bounded_String("abcdefgh"), -- 8 chs
|
B10.To_Bounded_String("ijklmn"), -- 6 chs
|
B10.To_Bounded_String("ijklmn"), -- 6 chs
|
Ada.Strings.Left);
|
Ada.Strings.Left);
|
|
|
if Result_String /= B10.To_Bounded_String("efghijklmn") then -- 10 chars
|
if Result_String /= B10.To_Bounded_String("efghijklmn") then -- 10 chars
|
Report.Failed("Incorrect truncation performed by Append - 4");
|
Report.Failed("Incorrect truncation performed by Append - 4");
|
end if;
|
end if;
|
|
|
-- Append (Bnd Str, Str)
|
-- Append (Bnd Str, Str)
|
Result_String :=
|
Result_String :=
|
B10.Append(B10.To_Bounded_String("abcdefghij"),
|
B10.Append(B10.To_Bounded_String("abcdefghij"),
|
"xyz",
|
"xyz",
|
Ada.Strings.Left);
|
Ada.Strings.Left);
|
|
|
if Result_String /= B10.To_Bounded_String("defghijxyz") then
|
if Result_String /= B10.To_Bounded_String("defghijxyz") then
|
Report.Failed("Incorrect truncation performed by Append - 5");
|
Report.Failed("Incorrect truncation performed by Append - 5");
|
end if;
|
end if;
|
|
|
-- Append (Char, Bnd Str)
|
-- Append (Char, Bnd Str)
|
|
|
Result_String := B10.Append('A',
|
Result_String := B10.Append('A',
|
B10.To_Bounded_String("abcdefghij"),
|
B10.To_Bounded_String("abcdefghij"),
|
Ada.Strings.Left);
|
Ada.Strings.Left);
|
|
|
if Result_String /= B10.To_Bounded_String("abcdefghij") then
|
if Result_String /= B10.To_Bounded_String("abcdefghij") then
|
Report.Failed("Incorrect truncation performed by Append - 6");
|
Report.Failed("Incorrect truncation performed by Append - 6");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
-- Append (Bnd Str, Bnd Str)
|
-- Append (Bnd Str, Bnd Str)
|
Result_String := B10.Append(FtoJ_Bnd_Str,
|
Result_String := B10.Append(FtoJ_Bnd_Str,
|
AtoJ_Bnd_Str,
|
AtoJ_Bnd_Str,
|
Ada.Strings.Right);
|
Ada.Strings.Right);
|
|
|
if Result_String /= B10.To_Bounded_String("fghijabcde") then
|
if Result_String /= B10.To_Bounded_String("fghijabcde") then
|
Report.Failed("Incorrect truncation performed by Append - 7");
|
Report.Failed("Incorrect truncation performed by Append - 7");
|
end if;
|
end if;
|
|
|
-- Append (Str, Bnd Str)
|
-- Append (Str, Bnd Str)
|
Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str),
|
Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str),
|
AtoJ_Bnd_Str,
|
AtoJ_Bnd_Str,
|
Ada.Strings.Right);
|
Ada.Strings.Right);
|
|
|
if Result_String /= B10.To_Bounded_String("abcdeabcde") then
|
if Result_String /= B10.To_Bounded_String("abcdeabcde") then
|
Report.Failed("Incorrect truncation performed by Append - 8");
|
Report.Failed("Incorrect truncation performed by Append - 8");
|
end if;
|
end if;
|
|
|
-- Append (Char, Bnd Str)
|
-- Append (Char, Bnd Str)
|
Result_String := B10.Append('A', AtoJ_Bnd_Str, Ada.Strings.Right);
|
Result_String := B10.Append('A', AtoJ_Bnd_Str, Ada.Strings.Right);
|
|
|
if Result_String /= B10.To_Bounded_String("Aabcdefghi") then
|
if Result_String /= B10.To_Bounded_String("Aabcdefghi") then
|
Report.Failed("Incorrect truncation performed by Append - 9");
|
Report.Failed("Incorrect truncation performed by Append - 9");
|
end if;
|
end if;
|
|
|
|
|
-- Function Index with non-Identity map.
|
-- Function Index with non-Identity map.
|
-- Evaluate the function Index with a non-identity map
|
-- Evaluate the function Index with a non-identity map
|
-- parameter which will cause mapping of the source parameter
|
-- parameter which will cause mapping of the source parameter
|
-- prior to the evaluation of the index position search.
|
-- prior to the evaluation of the index position search.
|
|
|
Location := B10.Index(Source => AtoJ_Bnd_Str, -- "abcdefghij"
|
Location := B10.Index(Source => AtoJ_Bnd_Str, -- "abcdefghij"
|
Pattern => "xy",
|
Pattern => "xy",
|
Going => Ada.Strings.Forward,
|
Going => Ada.Strings.Forward,
|
Mapping => CD_to_XY_Map); -- change "cd" to "xy"
|
Mapping => CD_to_XY_Map); -- change "cd" to "xy"
|
|
|
if Location /= 3 then
|
if Location /= 3 then
|
Report.Failed("Incorrect result from Index, non-Identity map - 1");
|
Report.Failed("Incorrect result from Index, non-Identity map - 1");
|
end if;
|
end if;
|
|
|
Location := B10.Index(B10.To_Bounded_String("AND IF MAN"),
|
Location := B10.Index(B10.To_Bounded_String("AND IF MAN"),
|
"an",
|
"an",
|
Ada.Strings.Backward,
|
Ada.Strings.Backward,
|
ASC.Lower_Case_Map);
|
ASC.Lower_Case_Map);
|
|
|
if Location /= 9 then
|
if Location /= 9 then
|
Report.Failed("Incorrect result from Index, non-Identity map - 2");
|
Report.Failed("Incorrect result from Index, non-Identity map - 2");
|
end if;
|
end if;
|
|
|
Location := B10.Index(Source => B10.To_Bounded_String("The the"),
|
Location := B10.Index(Source => B10.To_Bounded_String("The the"),
|
Pattern => "the",
|
Pattern => "the",
|
Going => Ada.Strings.Forward,
|
Going => Ada.Strings.Forward,
|
Mapping => ASC.Lower_Case_Map);
|
Mapping => ASC.Lower_Case_Map);
|
|
|
if Location /= 1 then
|
if Location /= 1 then
|
Report.Failed("Incorrect result from Index, non-Identity map - 3");
|
Report.Failed("Incorrect result from Index, non-Identity map - 3");
|
end if;
|
end if;
|
|
|
|
|
if B10.Index(B10.To_Bounded_String("abcd"), -- Pattern = Source
|
if B10.Index(B10.To_Bounded_String("abcd"), -- Pattern = Source
|
"abcd") /= 1 or
|
"abcd") /= 1 or
|
B10.Index(B10.To_Bounded_String("abc"), -- Pattern < Source
|
B10.Index(B10.To_Bounded_String("abc"), -- Pattern < Source
|
"abcd") /= 0 or
|
"abcd") /= 0 or
|
B10.Index(B10.Null_Bounded_String, -- Source = Null
|
B10.Index(B10.Null_Bounded_String, -- Source = Null
|
"abc") /= 0
|
"abc") /= 0
|
then
|
then
|
Report.Failed("Incorrect result from Index with string patterns");
|
Report.Failed("Incorrect result from Index with string patterns");
|
end if;
|
end if;
|
|
|
|
|
-- Function Index (for Sets).
|
-- Function Index (for Sets).
|
-- This version of Index uses Sets as the basis of the search.
|
-- This version of Index uses Sets as the basis of the search.
|
|
|
-- Test = Inside, Going = Forward (Default case).
|
-- Test = Inside, Going = Forward (Default case).
|
Location :=
|
Location :=
|
B10.Index(Source => B10.To_Bounded_String("abcdeabcde"),
|
B10.Index(Source => B10.To_Bounded_String("abcdeabcde"),
|
Set => CD_Set, -- set containing 'c' and 'd'
|
Set => CD_Set, -- set containing 'c' and 'd'
|
Test => Ada.Strings.Inside,
|
Test => Ada.Strings.Inside,
|
Going => Ada.Strings.Forward);
|
Going => Ada.Strings.Forward);
|
|
|
if not (Location = 3) then -- position of first 'c' in source.
|
if not (Location = 3) then -- position of first 'c' in source.
|
Report.Failed("Incorrect result from Index using Sets - 1");
|
Report.Failed("Incorrect result from Index using Sets - 1");
|
end if;
|
end if;
|
|
|
-- Test = Inside, Going = Backward.
|
-- Test = Inside, Going = Backward.
|
Location :=
|
Location :=
|
B10.Index(Source => B10."&"(AtoE_Bnd_Str, AtoE_Bnd_Str),
|
B10.Index(Source => B10."&"(AtoE_Bnd_Str, AtoE_Bnd_Str),
|
Set => CD_Set, -- set containing 'c' and 'd'
|
Set => CD_Set, -- set containing 'c' and 'd'
|
Test => Ada.Strings.Inside,
|
Test => Ada.Strings.Inside,
|
Going => Ada.Strings.Backward);
|
Going => Ada.Strings.Backward);
|
|
|
if not (Location = 9) then -- position of last 'd' in source.
|
if not (Location = 9) then -- position of last 'd' in source.
|
Report.Failed("Incorrect result from Index using Sets - 2");
|
Report.Failed("Incorrect result from Index using Sets - 2");
|
end if;
|
end if;
|
|
|
-- Test = Outside, Going = Forward.
|
-- Test = Outside, Going = Forward.
|
Location := B10.Index(B10.To_Bounded_String("deddacd"),
|
Location := B10.Index(B10.To_Bounded_String("deddacd"),
|
CD_Set,
|
CD_Set,
|
Test => Ada.Strings.Outside,
|
Test => Ada.Strings.Outside,
|
Going => Ada.Strings.Forward);
|
Going => Ada.Strings.Forward);
|
|
|
if Location /= 2 then -- position of 'e' in source.
|
if Location /= 2 then -- position of 'e' in source.
|
Report.Failed("Incorrect result from Index using Sets - 3");
|
Report.Failed("Incorrect result from Index using Sets - 3");
|
end if;
|
end if;
|
|
|
-- Test = Outside, Going = Backward.
|
-- Test = Outside, Going = Backward.
|
Location := B10.Index(B10.To_Bounded_String("deddacd"),
|
Location := B10.Index(B10.To_Bounded_String("deddacd"),
|
CD_Set,
|
CD_Set,
|
Ada.Strings.Outside,
|
Ada.Strings.Outside,
|
Ada.Strings.Backward);
|
Ada.Strings.Backward);
|
|
|
if Location /= 5 then -- correct position of 'a'.
|
if Location /= 5 then -- correct position of 'a'.
|
Report.Failed("Incorrect result from Index using Sets - 4");
|
Report.Failed("Incorrect result from Index using Sets - 4");
|
end if;
|
end if;
|
|
|
if B10.Index(B10.To_Bounded_String("cd"), -- Source = Set
|
if B10.Index(B10.To_Bounded_String("cd"), -- Source = Set
|
CD_Set) /= 1 or
|
CD_Set) /= 1 or
|
B10.Index(B10.To_Bounded_String("c"), -- Source < Set
|
B10.Index(B10.To_Bounded_String("c"), -- Source < Set
|
CD_Set) /= 1 or
|
CD_Set) /= 1 or
|
B10.Index(B10.Null_Bounded_String, -- Source = Null
|
B10.Index(B10.Null_Bounded_String, -- Source = Null
|
CD_Set) /= 0 or
|
CD_Set) /= 0 or
|
B10.Index(AtoE_Bnd_Str, -- "abcde"
|
B10.Index(AtoE_Bnd_Str, -- "abcde"
|
Maps.Null_Set) /= 0 or -- Null set
|
Maps.Null_Set) /= 0 or -- Null set
|
B10.Index(AtoE_Bnd_Str,
|
B10.Index(AtoE_Bnd_Str,
|
Maps.To_Set('x')) /= 0 -- No match.
|
Maps.To_Set('x')) /= 0 -- No match.
|
then
|
then
|
Report.Failed("Incorrect result from Index using Sets - 5");
|
Report.Failed("Incorrect result from Index using Sets - 5");
|
end if;
|
end if;
|
|
|
|
|
-- Function Count with non-Identity mapping.
|
-- Function Count with non-Identity mapping.
|
-- Evaluate the function Count with a non-identity map
|
-- Evaluate the function Count with a non-identity map
|
-- parameter which will cause mapping of the source parameter
|
-- parameter which will cause mapping of the source parameter
|
-- prior to the evaluation of the number of matching patterns.
|
-- prior to the evaluation of the number of matching patterns.
|
|
|
Total_Count :=
|
Total_Count :=
|
B10.Count(Source => B10.To_Bounded_String("abbabaabab"),
|
B10.Count(Source => B10.To_Bounded_String("abbabaabab"),
|
Pattern => "yz",
|
Pattern => "yz",
|
Mapping => AB_to_YZ_Map);
|
Mapping => AB_to_YZ_Map);
|
|
|
if Total_Count /= 4 then
|
if Total_Count /= 4 then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from function Count, non-Identity map - 1");
|
("Incorrect result from function Count, non-Identity map - 1");
|
end if;
|
end if;
|
|
|
-- And a few with identity maps as well.
|
-- And a few with identity maps as well.
|
|
|
if B10.Count(B10.To_Bounded_String("ABABABABAB"),
|
if B10.Count(B10.To_Bounded_String("ABABABABAB"),
|
"ABA",
|
"ABA",
|
Maps.Identity) /= 2 or
|
Maps.Identity) /= 2 or
|
B10.Count(B10.To_Bounded_String("ADCBADABCD"),
|
B10.Count(B10.To_Bounded_String("ADCBADABCD"),
|
"AB",
|
"AB",
|
Maps.To_Mapping("CD", "AB")) /= 5 or
|
Maps.To_Mapping("CD", "AB")) /= 5 or
|
B10.Count(B10.To_Bounded_String("aaaaaaaaaa"),
|
B10.Count(B10.To_Bounded_String("aaaaaaaaaa"),
|
"aaa") /= 3 or
|
"aaa") /= 3 or
|
B10.Count(B10.To_Bounded_String("XX"), -- Source < Pattern
|
B10.Count(B10.To_Bounded_String("XX"), -- Source < Pattern
|
"XXX",
|
"XXX",
|
Maps.Identity) /= 0 or
|
Maps.Identity) /= 0 or
|
B10.Count(AtoE_Bnd_Str, -- Source = Pattern
|
B10.Count(AtoE_Bnd_Str, -- Source = Pattern
|
"abcde") /= 1 or
|
"abcde") /= 1 or
|
B10.Count(B10.Null_Bounded_String, -- Source = Null
|
B10.Count(B10.Null_Bounded_String, -- Source = Null
|
" ") /= 0
|
" ") /= 0
|
then
|
then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from function Count, w,w/o mapping");
|
("Incorrect result from function Count, w,w/o mapping");
|
end if;
|
end if;
|
|
|
|
|
-- Procedure Translate
|
-- Procedure Translate
|
|
|
-- Partial mapping of source.
|
-- Partial mapping of source.
|
|
|
Test_String := B10.To_Bounded_String("abcdeabcab");
|
Test_String := B10.To_Bounded_String("abcdeabcab");
|
|
|
B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
|
B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
|
|
|
if Test_String /= B10.To_Bounded_String("yzcdeyzcyz") then
|
if Test_String /= B10.To_Bounded_String("yzcdeyzcyz") then
|
Report.Failed("Incorrect result from procedure Translate - 1");
|
Report.Failed("Incorrect result from procedure Translate - 1");
|
end if;
|
end if;
|
|
|
-- Total mapping of source.
|
-- Total mapping of source.
|
|
|
Test_String := B10.To_Bounded_String("abbaaababb");
|
Test_String := B10.To_Bounded_String("abbaaababb");
|
|
|
B10.Translate(Source => Test_String, Mapping => ASC.Upper_Case_Map);
|
B10.Translate(Source => Test_String, Mapping => ASC.Upper_Case_Map);
|
|
|
if Test_String /= B10.To_Bounded_String("ABBAAABABB") then
|
if Test_String /= B10.To_Bounded_String("ABBAAABABB") then
|
Report.Failed("Incorrect result from procedure Translate - 2");
|
Report.Failed("Incorrect result from procedure Translate - 2");
|
end if;
|
end if;
|
|
|
-- No mapping of source.
|
-- No mapping of source.
|
|
|
Test_String := B10.To_Bounded_String("xyzsypcc");
|
Test_String := B10.To_Bounded_String("xyzsypcc");
|
|
|
B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
|
B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
|
|
|
if Test_String /= B10.To_Bounded_String("xyzsypcc") then
|
if Test_String /= B10.To_Bounded_String("xyzsypcc") then
|
Report.Failed("Incorrect result from procedure Translate - 3");
|
Report.Failed("Incorrect result from procedure Translate - 3");
|
end if;
|
end if;
|
|
|
-- Map > 2 characters, partial mapping.
|
-- Map > 2 characters, partial mapping.
|
|
|
Test_String := B10.To_Bounded_String("have faith");
|
Test_String := B10.To_Bounded_String("have faith");
|
|
|
B10.Translate(Test_String,
|
B10.Translate(Test_String,
|
Maps.To_Mapping("aeiou", "AEIOU"));
|
Maps.To_Mapping("aeiou", "AEIOU"));
|
|
|
if Test_String /= B10.To_Bounded_String("hAvE fAIth") then
|
if Test_String /= B10.To_Bounded_String("hAvE fAIth") then
|
Report.Failed("Incorrect result from procedure Translate - 4");
|
Report.Failed("Incorrect result from procedure Translate - 4");
|
end if;
|
end if;
|
|
|
|
|
-- Function Replace_Slice
|
-- Function Replace_Slice
|
-- Evaluate function Replace_Slice with
|
-- Evaluate function Replace_Slice with
|
-- a variety of Truncation options.
|
-- a variety of Truncation options.
|
|
|
-- Drop = Error (Default)
|
-- Drop = Error (Default)
|
|
|
begin
|
begin
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
Result_String :=
|
Result_String :=
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
Low => 3,
|
Low => 3,
|
High => 5, -- 3-5, 3 chars.
|
High => 5, -- 3-5, 3 chars.
|
By => "xxxxxx"); -- more than 3.
|
By => "xxxxxx"); -- more than 3.
|
Report.Failed("Length_Error not raised by Function Replace_Slice");
|
Report.Failed("Length_Error not raised by Function Replace_Slice");
|
exception
|
exception
|
when AS.Length_Error => null; -- Correct exception raised.
|
when AS.Length_Error => null; -- Correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed
|
Report.Failed
|
("Incorrect exception raised by Function Replace_Slice");
|
("Incorrect exception raised by Function Replace_Slice");
|
end;
|
end;
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
Result_String :=
|
Result_String :=
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
Low => 7,
|
Low => 7,
|
High => 10, -- 7-10, 4 chars.
|
High => 10, -- 7-10, 4 chars.
|
By => "xxxxxx", -- 6 chars.
|
By => "xxxxxx", -- 6 chars.
|
Drop => Ada.Strings.Left);
|
Drop => Ada.Strings.Left);
|
|
|
if Result_String /= B10.To_Bounded_String("cdefxxxxxx") then -- drop a,b
|
if Result_String /= B10.To_Bounded_String("cdefxxxxxx") then -- drop a,b
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Function Replace Slice, Drop = Left");
|
("Incorrect result from Function Replace Slice, Drop = Left");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
Result_String :=
|
Result_String :=
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
Low => 2,
|
Low => 2,
|
High => 5, -- 2-5, 4 chars.
|
High => 5, -- 2-5, 4 chars.
|
By => "xxxxxx", -- 6 chars.
|
By => "xxxxxx", -- 6 chars.
|
Drop => Ada.Strings.Right);
|
Drop => Ada.Strings.Right);
|
|
|
if Result_String /= B10.To_Bounded_String("axxxxxxfgh") then -- drop i,j
|
if Result_String /= B10.To_Bounded_String("axxxxxxfgh") then -- drop i,j
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Function Replace Slice, Drop = Right");
|
("Incorrect result from Function Replace Slice, Drop = Right");
|
end if;
|
end if;
|
|
|
-- Low = High = Source'Last, "By" length = 1.
|
-- Low = High = Source'Last, "By" length = 1.
|
|
|
if B10.Replace_Slice(AtoE_Bnd_Str,
|
if B10.Replace_Slice(AtoE_Bnd_Str,
|
B10.To_String(AtoE_Bnd_Str)'Last,
|
B10.To_String(AtoE_Bnd_Str)'Last,
|
B10.To_String(AtoE_Bnd_Str)'Last,
|
B10.To_String(AtoE_Bnd_Str)'Last,
|
"X",
|
"X",
|
Ada.Strings.Error) /=
|
Ada.Strings.Error) /=
|
B10.To_Bounded_String("abcdX")
|
B10.To_Bounded_String("abcdX")
|
then
|
then
|
Report.Failed("Incorrect result from Function Replace_Slice");
|
Report.Failed("Incorrect result from Function Replace_Slice");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Procedure Replace_Slice
|
-- Procedure Replace_Slice
|
-- Evaluate procedure Replace_Slice with
|
-- Evaluate procedure Replace_Slice with
|
-- a variety of Truncation options.
|
-- a variety of Truncation options.
|
|
|
-- Drop = Error (Default)
|
-- Drop = Error (Default)
|
|
|
begin
|
begin
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
Low => 3,
|
Low => 3,
|
High => 5, -- 3-5, 3 chars.
|
High => 5, -- 3-5, 3 chars.
|
By => "xxxxxx"); -- more than 3.
|
By => "xxxxxx"); -- more than 3.
|
Report.Failed("Length_Error not raised by Procedure Replace_Slice");
|
Report.Failed("Length_Error not raised by Procedure Replace_Slice");
|
exception
|
exception
|
when AS.Length_Error => null; -- Correct exception raised.
|
when AS.Length_Error => null; -- Correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed
|
Report.Failed
|
("Incorrect exception raised by Procedure Replace_Slice");
|
("Incorrect exception raised by Procedure Replace_Slice");
|
end;
|
end;
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
Low => 7,
|
Low => 7,
|
High => 9, -- 7-9, 3 chars.
|
High => 9, -- 7-9, 3 chars.
|
By => "xxxxx", -- 5 chars.
|
By => "xxxxx", -- 5 chars.
|
Drop => Ada.Strings.Left);
|
Drop => Ada.Strings.Left);
|
|
|
if Test_String /= B10.To_Bounded_String("cdefxxxxxj") then -- drop a,b
|
if Test_String /= B10.To_Bounded_String("cdefxxxxxj") then -- drop a,b
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Procedure Replace Slice, Drop = Left");
|
("Incorrect result from Procedure Replace Slice, Drop = Left");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
|
Low => 1,
|
Low => 1,
|
High => 3, -- 1-3, 3chars.
|
High => 3, -- 1-3, 3chars.
|
By => "xxxx", -- 4 chars.
|
By => "xxxx", -- 4 chars.
|
Drop => Ada.Strings.Right);
|
Drop => Ada.Strings.Right);
|
|
|
if Test_String /= B10.To_Bounded_String("xxxxdefghi") then -- drop j
|
if Test_String /= B10.To_Bounded_String("xxxxdefghi") then -- drop j
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Procedure Replace Slice, Drop = Right");
|
("Incorrect result from Procedure Replace Slice, Drop = Right");
|
end if;
|
end if;
|
|
|
-- High = Source'First, Low > High (Insert before Low).
|
-- High = Source'First, Low > High (Insert before Low).
|
|
|
Test_String := AtoE_Bnd_Str;
|
Test_String := AtoE_Bnd_Str;
|
B10.Replace_Slice(Source => Test_String, -- "abcde"
|
B10.Replace_Slice(Source => Test_String, -- "abcde"
|
Low => B10.To_String(Test_String)'Last,
|
Low => B10.To_String(Test_String)'Last,
|
High => B10.To_String(Test_String)'First,
|
High => B10.To_String(Test_String)'First,
|
By => "XXXX", -- 4 chars.
|
By => "XXXX", -- 4 chars.
|
Drop => Ada.Strings.Right);
|
Drop => Ada.Strings.Right);
|
|
|
if Test_String /= B10.To_Bounded_String("abcdXXXXe") then
|
if Test_String /= B10.To_Bounded_String("abcdXXXXe") then
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Procedure Replace Slice");
|
("Incorrect result from Procedure Replace Slice");
|
end if;
|
end if;
|
|
|
|
|
|
|
-- Function Insert with Truncation
|
-- Function Insert with Truncation
|
-- Drop = Error (Default).
|
-- Drop = Error (Default).
|
|
|
begin
|
begin
|
Result_String :=
|
Result_String :=
|
B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij"
|
B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij"
|
Before => 2,
|
Before => 2,
|
New_Item => "xyz");
|
New_Item => "xyz");
|
Report.Failed("Length_Error not raised by Function Insert");
|
Report.Failed("Length_Error not raised by Function Insert");
|
exception
|
exception
|
when AS.Length_Error => null; -- Correct exception raised.
|
when AS.Length_Error => null; -- Correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Function Insert");
|
Report.Failed("Incorrect exception raised by Function Insert");
|
end;
|
end;
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
Result_String :=
|
Result_String :=
|
B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij"
|
B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij"
|
Before => 5,
|
Before => 5,
|
New_Item => "xyz", -- 3 additional chars.
|
New_Item => "xyz", -- 3 additional chars.
|
Drop => Ada.Strings.Left);
|
Drop => Ada.Strings.Left);
|
|
|
if B10.To_String(Result_String) /= "dxyzefghij" then -- drop a, b, c
|
if B10.To_String(Result_String) /= "dxyzefghij" then -- drop a, b, c
|
Report.Failed("Incorrect result from Function Insert, Drop = Left");
|
Report.Failed("Incorrect result from Function Insert, Drop = Left");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
Result_String :=
|
Result_String :=
|
B10.Insert(Source => B10.To_Bounded_String("abcdef"),
|
B10.Insert(Source => B10.To_Bounded_String("abcdef"),
|
Before => 2,
|
Before => 2,
|
New_Item => "vwxyz", -- 5 additional chars.
|
New_Item => "vwxyz", -- 5 additional chars.
|
Drop => Ada.Strings.Right);
|
Drop => Ada.Strings.Right);
|
|
|
if B10.To_String(Result_String) /= "avwxyzbcde" then -- drop f.
|
if B10.To_String(Result_String) /= "avwxyzbcde" then -- drop f.
|
Report.Failed("Incorrect result from Function Insert, Drop = Right");
|
Report.Failed("Incorrect result from Function Insert, Drop = Right");
|
end if;
|
end if;
|
|
|
-- Additional cases.
|
-- Additional cases.
|
|
|
if B10.Insert(B10.To_Bounded_String("a"), 1, " B") /=
|
if B10.Insert(B10.To_Bounded_String("a"), 1, " B") /=
|
B10.To_Bounded_String(" Ba") or
|
B10.To_Bounded_String(" Ba") or
|
B10.Insert(B10.Null_Bounded_String, 1, "abcde") /=
|
B10.Insert(B10.Null_Bounded_String, 1, "abcde") /=
|
AtoE_Bnd_Str or
|
AtoE_Bnd_Str or
|
B10.Insert(B10.To_Bounded_String("ab"), 2, "") /=
|
B10.Insert(B10.To_Bounded_String("ab"), 2, "") /=
|
B10.To_Bounded_String("ab")
|
B10.To_Bounded_String("ab")
|
then
|
then
|
Report.Failed("Incorrect result from Function Insert");
|
Report.Failed("Incorrect result from Function Insert");
|
end if;
|
end if;
|
|
|
|
|
-- Procedure Insert
|
-- Procedure Insert
|
|
|
-- Drop = Error (Default).
|
-- Drop = Error (Default).
|
begin
|
begin
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
B10.Insert(Source => Test_String, -- "abcdefghij"
|
B10.Insert(Source => Test_String, -- "abcdefghij"
|
Before => 9,
|
Before => 9,
|
New_Item => "wxyz",
|
New_Item => "wxyz",
|
Drop => Ada.Strings.Error);
|
Drop => Ada.Strings.Error);
|
Report.Failed("Length_Error not raised by Procedure Insert");
|
Report.Failed("Length_Error not raised by Procedure Insert");
|
exception
|
exception
|
when AS.Length_Error => null; -- Correct exception raised.
|
when AS.Length_Error => null; -- Correct exception raised.
|
when others =>
|
when others =>
|
Report.Failed("Incorrect exception raised by Procedure Insert");
|
Report.Failed("Incorrect exception raised by Procedure Insert");
|
end;
|
end;
|
|
|
-- Drop = Left
|
-- Drop = Left
|
|
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
B10.Insert(Source => Test_String, -- "abcdefghij"
|
B10.Insert(Source => Test_String, -- "abcdefghij"
|
Before => B10.Length(Test_String), -- before last char
|
Before => B10.Length(Test_String), -- before last char
|
New_Item => "xyz", -- 3 additional chars.
|
New_Item => "xyz", -- 3 additional chars.
|
Drop => Ada.Strings.Left);
|
Drop => Ada.Strings.Left);
|
|
|
if B10.To_String(Test_String) /= "defghixyzj" then -- drop a, b, c
|
if B10.To_String(Test_String) /= "defghixyzj" then -- drop a, b, c
|
Report.Failed("Incorrect result from Procedure Insert, Drop = Left");
|
Report.Failed("Incorrect result from Procedure Insert, Drop = Left");
|
end if;
|
end if;
|
|
|
-- Drop = Right
|
-- Drop = Right
|
|
|
Test_String := AtoJ_Bnd_Str;
|
Test_String := AtoJ_Bnd_Str;
|
B10.Insert(Source => Test_String,
|
B10.Insert(Source => Test_String,
|
Before => 4,
|
Before => 4,
|
New_Item => "yz", -- 2 additional chars.
|
New_Item => "yz", -- 2 additional chars.
|
Drop => Ada.Strings.Right);
|
Drop => Ada.Strings.Right);
|
|
|
if B10.To_String(Test_String) /= "abcyzdefgh" then -- drop i,j
|
if B10.To_String(Test_String) /= "abcyzdefgh" then -- drop i,j
|
Report.Failed
|
Report.Failed
|
("Incorrect result from Procedure Insert, Drop = Right");
|
("Incorrect result from Procedure Insert, Drop = Right");
|
end if;
|
end if;
|
|
|
-- Before = Source'First, New_Item length = 1.
|
-- Before = Source'First, New_Item length = 1.
|
|
|
Test_String := B10.To_Bounded_String(" abc ");
|
Test_String := B10.To_Bounded_String(" abc ");
|
B10.Insert(Test_String,
|
B10.Insert(Test_String,
|
B10.To_String(Test_String)'First,
|
B10.To_String(Test_String)'First,
|
"Z");
|
"Z");
|
|
|
if Test_String /= B10.To_Bounded_String("Z abc ") then
|
if Test_String /= B10.To_Bounded_String("Z abc ") then
|
Report.Failed("Incorrect result from Procedure Insert");
|
Report.Failed("Incorrect result from Procedure Insert");
|
end if;
|
end if;
|
|
|
|
|
exception
|
exception
|
when others => Report.Failed("Exception raised in Test_Block");
|
when others => Report.Failed("Exception raised in Test_Block");
|
end Test_Block;
|
end Test_Block;
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end CXA4008;
|
end CXA4008;
|
|
|