📄 cxa4022.a
字号:
-- Function Index with non-Identity map. -- Evaluate the function Index with a non-identity map -- parameter which will cause mapping of the source parameter -- prior to the evaluation of the index position search. Location := ASW.Index(Source => ASW.To_Unbounded_Wide_String (Equiv("abcdefghij")), Pattern => Equiv("xy"), Going => Ada.Strings.Forward, Mapping => CD_to_XY_Map); -- change "cd" to "xy" if Location /= 3 then Report.Failed("Incorrect result from Index, non-Identity map - 1"); end if; Location := ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("abcdabcdab")), Equiv("yz"), Ada.Strings.Backward, AB_to_YZ_Map); -- change all "ab" to "yz" if Location /= 9 then Report.Failed("Incorrect result from Index, non-Identity map - 2"); end if; -- A couple with identity maps (default) as well. if ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("abcd")), -- Pat = Src Equiv("abcd")) /= 1 or ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("abc")), -- Pat < Src Equiv("abcd")) /= 0 or ASW.Index(ASW.Null_Unbounded_Wide_String, -- Src = Null Equiv("abc")) /= 0 then Report.Failed ("Incorrect result from Index with wide string patterns"); end if; -- Function Index (for Sets). -- This version of Index uses Sets as the basis of the search. -- Test = Inside, Going = Forward (Default case). Location := ASW.Index(Source => ASW.To_Unbounded_Wide_String(Equiv("abcdeabcde")), Set => CD_Set); -- set containing 'c' and 'd' if not (Location = 3) then -- position of first 'c' in source. Report.Failed("Incorrect result from Index using Sets - 1"); end if; -- Test = Inside, Going = Backward. Location := ASW.Index(Source => ASW."&"(AtoE_Str, AtoE_Str), Set => CD_Set, -- set containing 'c' and 'd' Test => Ada.Strings.Inside, Going => Ada.Strings.Backward); if not (Location = 9) then -- position of last 'd' in source. Report.Failed("Incorrect result from Index using Sets - 2"); end if; -- Test = Outside, Going = Forward, Backward if ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("deddacd")), Wide_Maps.To_Set(Equiv("xydcgf")), Test => Ada.Strings.Outside, Going => Ada.Strings.Forward) /= 2 or ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("deddacd")), Wide_Maps.To_Set(Equiv("xydcgf")), Test => Ada.Strings.Outside, Going => Ada.Strings.Backward) /= 5 or ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("deddacd")), CD_Set, Ada.Strings.Outside, Ada.Strings.Backward) /= 5 then Report.Failed("Incorrect result from Index using Sets - 3"); end if; -- Default direction (forward) and mapping (identity). if ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("cd")), -- Source = Set CD_Set) /= 1 or ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("c")), -- Source < Set CD_Set) /= 1 or ASW.Index(ASW.Null_Unbounded_Wide_String, -- Source = Null CD_Set) /= 0 or ASW.Index(AtoE_Str, Wide_Maps.Null_Set) /= 0 or -- Null set ASW.Index(AtoE_Str, Wide_Maps.To_Set(Equiv('x'))) /= 0 -- No match. then Report.Failed("Incorrect result from Index using Sets - 4"); end if; -- Function Index using access-to-subprogram mapping. -- Evaluate the function Index with an access value that supplies the -- mapping function for this version of Index. Map_Ptr := AB_to_US_Mapping_Function'Access; Location := ASW.Index(Source => ASW.To_Unbounded_Wide_String (Equiv("xAxabbxax xaax _cx")), Pattern => Equiv("_x"), Going => Ada.Strings.Forward, Mapping => Map_Ptr); -- change 'a'or 'b' to '_' if Location /= 6 then -- location of "bx" substring Report.Failed("Incorrect result from Index, access value map - 1"); end if; Map_Ptr := AB_to_Blank_Mapping_Function'Access; Location := ASW.Index(ASW.To_Unbounded_Wide_String (Equiv("ccacdcbbcdacc")), Equiv("cd "), Ada.Strings.Backward, Map_Ptr); -- change 'a' or 'b' to ' ' if Location /= 9 then Report.Failed("Incorrect result from Index, access value map - 2"); end if; if ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("abcd")), Equiv(" cd"), Ada.Strings.Forward, Map_Ptr) /= 1 or ASW.Index(ASW.To_Unbounded_Wide_String(Equiv("abc")), Equiv(" c "), -- No match Ada.Strings.Backward, Map_Ptr) /= 0 then Report.Failed("Incorrect result from Index, access value map - 3"); end if; -- Function Count -- Determine the number of characters in the unbounded wide string that -- are contained in the set. Matching_Letters := ASW.Count(Source => Magic_String, Set => ABCD_Set); if Matching_Letters /= 9 then Report.Failed ("Incorrect result from Function Count with Set parameter"); end if; -- Determine the number of occurrences of the following pattern wide -- strings in the unbounded wide string Magic_String. if ASW.Count(Magic_String, Equiv("ab")) /= (ASW.Count(Magic_String, Equiv("ac")) + ASW.Count(Magic_String, Equiv("ad"))) or ASW.Count(Magic_String, Equiv("ab")) /= 2 then Report.Failed ("Incorrect result from Function Count, wide string parameter"); end if; -- Function Count with non-Identity mapping. -- Evaluate the function Count with a non-identity map -- parameter which will cause mapping of the source parameter -- prior to the evaluation of the number of matching patterns. Total_Count := ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("abbabbabbabba")), Pattern => Equiv("yz"), Mapping => AB_to_YZ_Map); if Total_Count /= 4 then Report.Failed ("Incorrect result from function Count, non-Identity map - 1"); end if; if ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("ADCBADABCD")), Equiv("AB"), Wide_Maps.To_Mapping(Equiv("CD"), Equiv("AB"))) /= 5 or ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("dcccddcdccdddccccd")), Equiv("xxy"), CD_to_XY_Map) /= 3 then Report.Failed ("Incorrect result from function Count, non-Identity map - 2"); end if; -- And a few with identity Wide_Maps as well. if ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("ABABABABAB")), Equiv("ABA"), Wide_Maps.Identity) /= 2 or ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("aaaaaaaaaa")), Equiv("aaa")) /= 3 or ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("XX")), -- Src < Pat Equiv("XXX"), Wide_Maps.Identity) /= 0 or ASW.Count(AtoE_Str, -- Source = Pattern Equiv("abcde")) /= 1 or ASW.Count(ASW.Null_Unbounded_Wide_String, -- Source = Null Equiv(" ")) /= 0 then Report.Failed ("Incorrect result from function Count, w,w/o mapping"); end if; -- Function Count using access-to-subprogram mapping. -- Evaluate the function Count with an access value specifying the -- mapping that is going to occur to Source. Map_Ptr := AB_to_US_Mapping_Function'Access; Total_Count := ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("abcbacbadbaAbbB")), Pattern => Equiv("__"), Mapping => Map_Ptr); -- change 'a' and 'b' to '_' if Total_Count /= 5 then Report.Failed ("Incorrect result from function Count, access value map - 1"); end if; Map_Ptr := AB_to_Blank_Mapping_Function'Access; if ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("cccaccBcbcaccacAc")), Equiv("c c"), Map_Ptr) /= 3 or ASW.Count(ASW.To_Unbounded_Wide_String (Equiv("aBBAAABaBBBBAaBABBABaBBbBB")), Equiv(" BB"), Map_Ptr) /= 4 or ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("aaaaaaaaaa")), Equiv(" "), Map_Ptr) /= 3 or ASW.Count(ASW.To_Unbounded_Wide_String(Equiv("XX")), -- Src < Pat Equiv("XX "), Map_Ptr) /= 0 or ASW.Count(AtoE_Str, -- Source'Length = Pattern'Length Equiv(" cde"), Map_Ptr) /= 1 then Report.Failed ("Incorrect result from function Count, access value map - 3"); end if; exception when others => Report.Failed ("Exception raised in Test_Block"); end Test_Block; Report.Result;end CXA4022;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -