📄 cxa4019.a
字号:
if Test_String /= B10.To_Bounded_Wide_String("") then Report.Failed ("Incorrect result from procedure Translate w/map ptr - 5"); end if; -- Function Translate with access-to-subprogram mapping. -- Use the version of Function Translate that takes an -- access-to-subprogram parameter to perform the Source mapping. -- Partial mapping of source. if B10.Translate(Source => B10.To_Bounded_Wide_String("cateatdog"), Mapping => Map_Ptr) /= B10.To_Bounded_Wide_String("cateatcat") then Report.Failed ("Incorrect result from function Translate w/map ptr - 1"); end if; if B10.Translate(B10.To_Bounded_Wide_String("cadogtac"), Map_Ptr) /= B10.To_Bounded_Wide_String("cacattac") then Report.Failed ("Incorrect result from function Translate w/map ptr - 2"); end if; -- Total mapping of source. if B10.Translate(Source => B10.To_Bounded_Wide_String("dogodggdo"), Mapping => Map_Ptr) /= B10.To_Bounded_Wide_String("catacttca") then Report.Failed ("Incorrect result from function Translate w/map ptr- 3"); end if; -- No mapping of source. if B10.Translate(Source => B10.To_Bounded_Wide_String(" DOG cat "), Mapping => Map_Ptr) /= B10.To_Bounded_Wide_String(" DOG cat ") then Report.Failed ("Incorrect result from function Translate w/map ptr - 4"); end if; if B10.Translate(B10.To_Bounded_Wide_String("d "), Map_Ptr) /= B10.To_Bounded_Wide_String("c ") or B10.Translate(B10.To_Bounded_Wide_String(" god"), Map_Ptr) /= B10.To_Bounded_Wide_String(" tac") or B10.Translate(B10.To_Bounded_Wide_String("d o g D og"), Map_Ptr) /= B10.To_Bounded_Wide_String("c a t D at") or B10.Translate(B10.To_Bounded_Wide_String(" "), Map_Ptr) /= B10.To_Bounded_Wide_String(" ") or B10.Translate(B10.To_Bounded_Wide_String("dddddddddd"), Map_Ptr) /= B10.To_Bounded_Wide_String("cccccccccc") then Report.Failed ("Incorrect result from function Translate w/map ptr - 5"); end if; if B10.Translate(Source => B10.Null_Bounded_Wide_String, Mapping => Map_Ptr) /= B10.To_Bounded_Wide_String("") then Report.Failed ("Incorrect result from function Translate w/map ptr - 6"); end if; -- Function Replace_Slice -- Evaluate function Replace_Slice with -- a variety of Truncation options. -- Drop = Error (Default) begin Test_String := AtoJ_Bnd_Str; Result_String := B10.Replace_Slice(Source => Test_String, Low => 3, High => 5, -- 3-5, 3 chars. By => Equiv("xxxxxx")); -- more than 3. Report.Failed("Length_Error not raised by Function Replace_Slice"); exception when AS.Length_Error => null; -- Correct exception raised. when others => Report.Failed ("Incorrect exception raised by Function Replace_Slice"); end; -- Drop = Left Result_String := B10.Replace_Slice(Source => Test_String, Low => 7, High => 10, -- 7-10, 4 chars. By => Equiv("xxxxxx"), -- 6 chars. Drop => Ada.Strings.Left); if Result_String /= B10.To_Bounded_Wide_String(Equiv("cdefxxxxxx")) -- drop a,b then Report.Failed ("Incorrect result from Function Replace Slice, Drop = Left"); end if; -- Drop = Right Result_String := B10.Replace_Slice(Source => Test_String, Low => 2, High => 5, -- 2-5, 4 chars. By => Equiv("xxxxxx"), -- 6 chars. Drop => Ada.Strings.Right); if Result_String /= B10.To_Bounded_Wide_String(Equiv("axxxxxxfgh")) -- drop i,j then Report.Failed ("Incorrect result from Function Replace Slice, Drop = Right"); end if; -- Low = High = Source'Last, "By" length = 1. if B10.Replace_Slice(AtoE_Bnd_Str, B10.To_Wide_String(AtoE_Bnd_Str)'Last, B10.To_Wide_String(AtoE_Bnd_Str)'Last, Equiv("X"), Ada.Strings.Error) /= B10.To_Bounded_Wide_String(Equiv("abcdX")) then Report.Failed("Incorrect result from Function Replace_Slice"); end if; -- Index_Error raised when High < Source'First - 1. begin Test_String := B10.Replace_Slice(AtoE_Bnd_Str, B10.To_Wide_String(AtoE_Bnd_Str)'First, B10.To_Wide_String(AtoE_Bnd_Str)'First - 2, Equiv("hijklm")); Report.Failed("Index_Error not raised by Function Replace_Slice"); exception when AS.Index_Error => null; -- OK, expected exception when Constraint_Error => null; -- Also OK, since RM is not clear when others => Report.Failed ("Incorrect exception raised by Function Replace_Slice"); end; -- Procedure Replace_Slice -- Evaluate procedure Replace_Slice with -- a variety of Truncation options. -- Drop = Error (Default) begin Test_String := AtoJ_Bnd_Str; B10.Replace_Slice(Source => Test_String, Low => 3, High => 5, -- 3-5, 3 chars. By => Equiv("xxxxxx")); -- more than 3. Report.Failed("Length_Error not raised by Procedure Replace_Slice"); exception when AS.Length_Error => null; -- Correct exception raised. when others => Report.Failed ("Incorrect exception raised by Procedure Replace_Slice"); end; -- Drop = Left Test_String := AtoJ_Bnd_Str; B10.Replace_Slice(Source => Test_String, Low => 7, High => 9, -- 7-9, 3 chars. By => Equiv("xxxxx"), -- 5 chars. Drop => Ada.Strings.Left); if Test_String /= B10.To_Bounded_Wide_String(Equiv("cdefxxxxxj")) -- drop a,b then Report.Failed ("Incorrect result from Procedure Replace Slice, Drop = Left"); end if; -- Drop = Right Test_String := AtoJ_Bnd_Str; B10.Replace_Slice(Source => Test_String, Low => 1, High => 3, -- 1-3, 3chars. By => Equiv("xxxx"), -- 4 chars. Drop => Ada.Strings.Right); if Test_String /= B10.To_Bounded_Wide_String(Equiv("xxxxdefghi")) -- drop j then Report.Failed ("Incorrect result from Procedure Replace Slice, Drop = Right"); end if; -- High = Source'First, Low > High (Insert before Low). Test_String := AtoE_Bnd_Str; B10.Replace_Slice(Source => Test_String, Low => B10.To_Wide_String(Test_String)'Last, High => B10.To_Wide_String(Test_String)'First, By => Equiv("XXXX"), -- 4 chars. Drop => Ada.Strings.Right); if Test_String /= B10.To_Bounded_Wide_String(Equiv("abcdXXXXe")) then Report.Failed ("Incorrect result from Procedure Replace Slice"); end if; -- Function Insert with Truncation -- Drop = Error (Default). begin Result_String := B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij" Before => 2, New_Item => Equiv("xyz")); Report.Failed("Length_Error not raised by Function Insert"); exception when AS.Length_Error => null; -- Correct exception raised. when others => Report.Failed("Incorrect exception raised by Function Insert"); end; -- Drop = Left Result_String := B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij" Before => 5, New_Item => Equiv("xyz"), -- 3 additional chars. Drop => Ada.Strings.Left); if B10.To_Wide_String(Result_String) /= Equiv("dxyzefghij") then Report.Failed("Incorrect result from Function Insert, Drop = Left"); end if; -- Drop = Right Result_String := B10.Insert(Source => B10.To_Bounded_Wide_String("abcdef"), Before => 2, New_Item => "vwxyz", -- 5 additional chars. Drop => Ada.Strings.Right); if B10.To_Wide_String(Result_String) /= "avwxyzbcde" then -- drop f. Report.Failed("Incorrect result from Function Insert, Drop = Right"); end if; -- Additional cases. if B10.Insert(B10.To_Bounded_Wide_String("a"), 1, " B") /= B10.To_Bounded_Wide_String(" Ba") or B10.Insert(B10.Null_Bounded_Wide_String, 1, Equiv("abcde")) /= AtoE_Bnd_Str or B10.Insert(B10.To_Bounded_Wide_String("ab"), 2, "") /= B10.To_Bounded_Wide_String("ab") then Report.Failed("Incorrect result from Function Insert"); end if; -- Procedure Insert -- Drop = Error (Default). begin Test_String := AtoJ_Bnd_Str; B10.Insert(Source => Test_String, Before => 9, New_Item => Equiv("wxyz"), Drop => Ada.Strings.Error); Report.Failed("Length_Error not raised by Procedure Insert"); exception when AS.Length_Error => null; -- Correct exception raised. when others => Report.Failed("Incorrect exception raised by Procedure Insert"); end; -- Drop = Left Test_String := AtoJ_Bnd_Str; B10.Insert(Source => Test_String, Before => B10.Length(Test_String), -- before last char New_Item => Equiv("xyz"), -- 3 additional chars. Drop => Ada.Strings.Left); if B10.To_Wide_String(Test_String) /= Equiv("defghixyzj") then Report.Failed("Incorrect result from Procedure Insert, Drop = Left"); end if; -- Drop = Right Test_String := AtoJ_Bnd_Str; B10.Insert(Source => Test_String, Before => 4, New_Item => Equiv("yz"), -- 2 additional chars. Drop => Ada.Strings.Right); if B10.To_Wide_String(Test_String) /= Equiv("abcyzdefgh") then Report.Failed ("Incorrect result from Procedure Insert, Drop = Right"); end if; -- Before = Source'First, New_Item length = 1. Test_String := B10.To_Bounded_Wide_String(" abc "); B10.Insert(Test_String, B10.To_Wide_String(Test_String)'First, "Z"); if Test_String /= B10.To_Bounded_Wide_String("Z abc ") then Report.Failed("Incorrect result from Procedure Insert"); end if; exception when others => Report.Failed("Exception raised in Test_Block"); end Test_Block; Report.Result;end CXA4019;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -