📄 cxa4020.a
字号:
("Incorrect result from Fn Trim - Sets, Left & Right side - 2"); end if; -- Ensure that characters contained in the sets are not trimmed from -- the "interior" of the bounded wide string, just the appropriate ends. if B10.Trim(B10.To_Bounded_Wide_String(Translate("cdabdxabxy")), CD_Set, XY_Set) /= B10.To_Bounded_Wide_String(Translate("abdxab")) then Report.Failed ("Incorrect result from Fn Trim - Sets, Left & Right side - 3"); end if; -- Trim characters in set from right side only. No change to Left side. if B10.Trim(B10.To_Bounded_Wide_String(Translate("abxyzddcd")), XY_Set, CD_Set) /= B10.To_Bounded_Wide_String(Translate("abxyz")) then Report.Failed ("Incorrect result from Fn Trim - Sets, Right side"); end if; -- Trim no characters on either side of the bounded string. Result_String := B10.Trim(AtoJ_Bnd_Str, CD_Set, XY_Set); if Result_String /= AtoJ_Bnd_Str then Report.Failed("Incorrect result from Fn Trim - Sets, Neither side"); end if; if B10.Trim(AtoE_Bnd_Str, Maps.Null_Set, Maps.Null_Set) /= AtoE_Bnd_Str or B10.Trim(B10.To_Bounded_Wide_String(Translate("dcddcxyyxx")), CD_Set, XY_Set) /= B10.Null_Bounded_Wide_String then Report.Failed("Incorrect result from Function Trim"); end if; -- Procedure Trim using Sets -- Trim characters in sets from both sides of the bounded wide string. Test_String := B10.To_Bounded_Wide_String(Translate("dcabbayx")); B10.Trim(Source => Test_String, Left => CD_Set, Right => XY_Set); if Test_String /= B10.To_Bounded_Wide_String(Translate("abba")) then Report.Failed ("Incorrect result from Proc Trim - Sets, Left & Right side - 1"); end if; -- Ensure that the characters in the set provided as the actual to -- parameter Right are not trimmed from the left side of the bounded -- wide string; likewise for the opposite side. Only "cd" trimmed -- from left side, and only "xy" trimmed from right side. Test_String := B10.To_Bounded_Wide_String(Translate("cdxyabcdxy")); B10.Trim(Test_String, CD_Set, XY_Set); if Test_String /= B10.To_Bounded_Wide_String(Translate("xyabcd")) then Report.Failed ("Incorrect result from Proc Trim - Sets, Left & Right side - 2"); end if; -- Ensure that characters contained in the sets are not trimmed from -- the "interior" of the bounded wide string, just the appropriate ends. Test_String := B10.To_Bounded_Wide_String(Translate("cdabdxabxy")); B10.Trim(Test_String, CD_Set, XY_Set); if not (Test_String = B10.To_Bounded_Wide_String(Translate("abdxab"))) then Report.Failed ("Incorrect result from Proc Trim - Sets, Left & Right side - 3"); end if; -- Trim characters in set from Left side only. No change to Right side. Test_String := B10.To_Bounded_Wide_String(Translate("cccdabxyz")); B10.Trim(Test_String, CD_Set, XY_Set); if Test_String /= B10.To_Bounded_Wide_String(Translate("abxyz")) then Report.Failed ("Incorrect result from Proc Trim for Sets, Left side only"); end if; -- Trim no characters on either side of the bounded wide string. Test_String := AtoJ_Bnd_Str; B10.Trim(Test_String, CD_Set, CD_Set); if Test_String /= AtoJ_Bnd_Str then Report.Failed("Incorrect result from Proc Trim-Sets, Neither side"); end if; -- Function Head with Truncation -- Drop = Error (Default). begin Result_String := B10.Head(Source => AtoJ_Bnd_Str, -- max length Count => B10.Length(AtoJ_Bnd_Str) + 1, Pad => Translate('X')); Report.Failed("Length_Error not raised by Function Head"); exception when AS.Length_Error => null; -- Expected exception raised. when others => Report.Failed("Incorrect exception raised by Function Head"); end; -- Drop = Left -- Pad characters (5) are appended to the right end of the bounded -- wide string (which is initially at its maximum length), then the -- first five characters of the intermediate result are dropped to -- conform to the maximum size limit of the bounded wide string (10). Result_String := B10.Head(B10.To_Bounded_Wide_String(Translate("ABCDEFGHIJ")), 15, Translate('x'), Ada.Strings.Left); if Result_String /= B10.To_Bounded_Wide_String(Translate("FGHIJxxxxx")) then Report.Failed("Incorrect result from Function Head, Drop = Left"); end if; -- Drop = Right -- Pad characters (6) are appended to the left end of the bounded -- wide string (which is initially at one less than its maximum length), -- then the last five characters of the intermediate result are dropped -- (which in this case are the pad characters) to conform to the -- maximum size limit of the bounded wide string (10). Result_String := B10.Head(B10.To_Bounded_Wide_String(Translate("ABCDEFGHI")), 15, Translate('x'), Ada.Strings.Right); if Result_String /= B10.To_Bounded_Wide_String(Translate("ABCDEFGHIx")) then Report.Failed("Incorrect result from Function Head, Drop = Right"); end if; -- Additional cases. if B10.Head(B10.Null_Bounded_Wide_String, 5, Translate('a')) /= B10.To_Bounded_Wide_String(Translate("aaaaa")) or B10.Head(AtoE_Bnd_Str, B10.Length(AtoE_Bnd_Str)) /= AtoE_Bnd_Str then Report.Failed("Incorrect result from Function Head"); end if; -- Function Tail with Truncation -- Drop = Error (Default Case) begin Result_String := B10.Tail(Source => AtoJ_Bnd_Str, -- max length Count => B10.Length(AtoJ_Bnd_Str) + 1, Pad => Ada.Strings.Wide_Space, Drop => Ada.Strings.Error); Report.Failed("Length_Error not raised by Function Tail"); exception when AS.Length_Error => null; -- Expected exception raised. when others => Report.Failed("Incorrect exception raised by Function Tail"); end; -- Drop = Left -- Pad characters (5) are appended to the left end of the bounded wide -- string (which is initially at two less than its maximum length), -- then the first three characters of the intermediate result (in this -- case, 3 pad characters) are dropped. Result_String := B10.Tail(B10.To_Bounded_Wide_String(Translate("ABCDEFGH")), 13, Translate('x'), Ada.Strings.Left); if Result_String /= B10.To_Bounded_Wide_String(Translate("xxABCDEFGH")) then Report.Failed("Incorrect result from Function Tail, Drop = Left"); end if; -- Drop = Right -- Pad characters (3) are appended to the left end of the bounded wide -- string (which is initially at its maximum length), then the last -- three characters of the intermediate result are dropped. Result_String := B10.Tail(B10.To_Bounded_Wide_String(Translate("ABCDEFGHIJ")), 13, Translate('x'), Ada.Strings.Right); if Result_String /= B10.To_Bounded_Wide_String(Translate("xxxABCDEFG")) then Report.Failed("Incorrect result from Function Tail, Drop = Right"); end if; -- Additional cases. if B10.Tail(B10.Null_Bounded_Wide_String, 3, Translate(' ')) /= B10.To_Bounded_Wide_String(Translate(" ")) or B10.Tail(AtoE_Bnd_Str, B10.To_Wide_String(AtoE_Bnd_Str)'First) /= B10.To_Bounded_Wide_String(Translate("e")) then Report.Failed("Incorrect result from Function Tail"); end if; -- Function Replicate (#, Char) with Truncation -- Drop = Error (Default). begin Result_String := B10.Replicate(Count => B10.Max_Length + 5, Item => Translate('A'), Drop => AS.Error); Report.Failed ("Length_Error not raised by Replicate for characters"); exception when AS.Length_Error => null; -- Expected exception raised. when others => Report.Failed ("Incorrect exception raised by Replicate for characters"); end; -- Drop = Left, Right -- Since this version of Replicate uses wide character parameters, the -- result after truncation from left or right will appear the same. -- The result will be a 10 character bounded wide string, composed of -- 10 "Item" wide characters. if B10.Replicate(Count => 20, Item => Translate('A'), Drop => Ada.Strings.Left) /= B10.Replicate(15, Translate('A'), Ada.Strings.Right) then Report.Failed("Incorrect result from Replicate for characters - 1"); end if; -- Blank-filled, 10 character bounded wide strings. if B10.Replicate(B10.Max_Length + 1, Translate(' '), Drop => Ada.Strings.Left) /= B10.Replicate(B10.Max_Length, Ada.Strings.Wide_Space) then Report.Failed("Incorrect result from Replicate for characters - 2"); end if; -- Additional cases. if B10.Replicate(0, Translate('a')) /= B10.Null_Bounded_Wide_String or B10.Replicate(1, Translate('a')) /= B10.To_Bounded_Wide_String(Translate("a")) then Report.Failed("Incorrect result from Replicate for characters - 3"); end if; -- Function Replicate (#, String) with Truncation -- Drop = Error (Default). begin Result_String := B10.Replicate(Count => 5, -- result would be 15. Item => Translate("abc")); Report.Failed ("Length_Error not raised by Replicate for wide strings"); exception when AS.Length_Error => null; -- Expected exception raised. when others => Report.Failed ("Incorrect exception raised by Replicate for wide strings"); end; -- Drop = Left Result_String := B10.Replicate(3, Translate("abcd"), Ada.Strings.Left); if Result_String /= B10.To_Bounded_Wide_String(Translate("cdabcdabcd")) then Report.Failed ("Incorrect result from Replicate for wide strings, Drop = Left"); end if; -- Drop = Right Result_String := B10.Replicate(3, Translate("abcd"), Ada.Strings.Right); if Result_String /= B10.To_Bounded_Wide_String(Translate("abcdabcdab")) then Report.Failed ("Incorrect result from Replicate for wide strings, Drop = Right"); end if; -- Additional cases. if B10.Replicate(5, Translate("X")) /= B10.To_Bounded_Wide_String(Translate("XXXXX")) or B10.Replicate(10, "") /= B10.Null_Bounded_Wide_String or B10.Replicate(0, Translate("ab")) /= B10.Null_Bounded_Wide_String then Report.Failed("Incorrect result from Replicate for wide strings"); end if; exception when others => Report.Failed("Exception raised in Test_Block"); end Test_Block; Report.Result;end CXA4020;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -