📄 cxa4009.a
字号:
if B10.Trim(B10.To_Bounded_String("cdabdxabxy"), CD_Set, XY_Set) /= B10.To_Bounded_String("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_String("abxyzddcd"), XY_Set, CD_Set) /= B10.To_Bounded_String("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_String("dcddcxyyxx"), CD_Set, XY_Set) /= B10.Null_Bounded_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 string. Test_String := B10.To_Bounded_String("dcabbayx"); B10.Trim(Source => Test_String, Left => CD_Set, Right => XY_Set); if Test_String /= B10.To_Bounded_String("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 -- string; likewise for the opposite side. Only "cd" trimmed from left -- side, and only "xy" trimmed from right side. Test_String := B10.To_Bounded_String("cdxyabcdxy"); B10.Trim(Test_String, CD_Set, XY_Set); if Test_String /= B10.To_Bounded_String("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 string, just the appropriate ends. Test_String := B10.To_Bounded_String("cdabdxabxy"); B10.Trim(Test_String, CD_Set, XY_Set); if not (Test_String = B10.To_Bounded_String("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_String("cccdabxyz"); B10.Trim(Test_String, CD_Set, XY_Set); if Test_String /= B10.To_Bounded_String("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 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 => '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 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 string (10). Result_String := B10.Head(B10.To_Bounded_String("ABCDEFGHIJ"), 15, 'x', Ada.Strings.Left); if Result_String /= B10.To_Bounded_String("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 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 string (10). Result_String := B10.Head(B10.To_Bounded_String("ABCDEFGHI"), 15, 'x', Ada.Strings.Right); if Result_String /= B10.To_Bounded_String("ABCDEFGHIx") then Report.Failed("Incorrect result from Function Head, Drop = Right"); end if; -- Additional cases. if B10.Head(B10.Null_Bounded_String, 5) /= B10.To_Bounded_String(" ") 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.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 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_String("ABCDEFGH"), -- 8 ch 13, 'x', Ada.Strings.Left); if Result_String /= B10.To_Bounded_String("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 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_String("ABCDEFGHIJ"), 13, 'x', Ada.Strings.Right); if Result_String /= B10.To_Bounded_String("xxxABCDEFG") then Report.Failed("Incorrect result from Function Tail, Drop = Right"); end if; -- Additional cases. if B10.Tail(B10.Null_Bounded_String, 3, ' ') /= B10.To_Bounded_String(" ") or B10.Tail(AtoE_Bnd_Str, B10.To_String(AtoE_Bnd_Str)'First) /= B10.To_Bounded_String("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 => '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 character parameters, the -- result after truncation from left or right will appear the same. -- The result will be a 10 character bounded string, composed of 10 -- "Item" characters. if B10.Replicate(Count => 20, Item => 'A', Drop => Ada.Strings.Left) /= B10.Replicate(15, 'A', Ada.Strings.Right) then Report.Failed("Incorrect result from Replicate for characters - 1"); end if; -- Blank-filled 10 character bounded strings. if B10.Replicate(B10.Max_Length + 1, ' ', Drop => Ada.Strings.Left) /= B10.Replicate(B10.Max_Length, Ada.Strings.Space) then Report.Failed("Incorrect result from Replicate for characters - 2"); end if; -- Additional cases. if B10.Replicate(0, 'a') /= B10.Null_Bounded_String or B10.Replicate(1, 'a') /= B10.To_Bounded_String("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 => "abc"); Report.Failed ("Length_Error not raised by Replicate for strings"); exception when AS.Length_Error => null; -- Expected exception raised. when others => Report.Failed ("Incorrect exception raised by Replicate for strings"); end; -- Drop = Left Result_String := B10.Replicate(3, "abcd", Drop => Ada.Strings.Left); if Result_String /= B10.To_Bounded_String("cdabcdabcd") then Report.Failed ("Incorrect result from Replicate for strings, Drop = Left"); end if; -- Drop = Right Result_String := B10.Replicate(3, "abcd", Drop => Ada.Strings.Right); if Result_String /= B10.To_Bounded_String("abcdabcdab") then Report.Failed ("Incorrect result from Replicate for strings, Drop = Right"); end if; -- Additional cases. if B10.Replicate(10, "X") /= B10.To_Bounded_String("XXXXXXXXXX") or B10.Replicate(10, "") /= B10.Null_Bounded_String or B10.Replicate( 0, "ab") /= B10.Null_Bounded_String then Report.Failed("Incorrect result from Replicate for strings"); end if; exception when others => Report.Failed("Exception raised in Test_Block"); end Test_Block; Report.Result;end CXA4009;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -