cxa4015.a
来自「linux下编程用 编译软件」· A 代码 · 共 581 行 · 第 1/2 页
A
581 行
-- translation. if Location /= 8 then Report.Failed ("Incorrect result from Index w/map ptr going Backward"); end if; Location := ASF.Index("ddkkddakcdakdefcadckdfzaaqd", "zq", -- slice 7..8 Ada.Strings.Forward, Map_Ptr); -- perform 'a' to 'z', 'k' to 'q' -- translation. if Location /= 7 then Report.Failed ("Incorrect result from Index w/map ptr going Forward"); end if; if ASF.Index("aakkzq", "zq", Ada.Strings.Forward, Map_Ptr) /= 2 or ASF.Index("qzedka", "qz", Ada.Strings.Backward, Map_Ptr) /= 5 or ASF.Index("zazaza", "zzzz", Ada.Strings.Backward, Map_Ptr) /= 3 or ASF.Index("kka", "qqz", Ada.Strings.Forward, Map_Ptr) /= 1 then Report.Failed("Incorrect result from Index w/map ptr"); end if; -- Check when the pattern wide string is not found in the source. if ASF.Index("akzqef", "kzq", Ada.Strings.Forward, Map_Ptr) /= 0 or ASF.Index("abcde", "abcdef", Ada.Strings.Backward, Map_Ptr) /= 0 or ASF.Index("xyz", "akzde", Ada.Strings.Backward, Map_Ptr) /= 0 or ASF.Index("", "zq", Ada.Strings.Forward, Map_Ptr) /= 0 or ASF.Index("akcde", " ", Ada.Strings.Backward, Map_Ptr) /= 0 then Report.Failed ("Incorrect result from Index w/map ptr, no pattern match"); end if; -- Check that Pattern_Error is raised when the pattern is a -- null Wide_String. begin Location := ASF.Index("akzqefakqzef", "", -- null pattern Wide_String. Ada.Strings.Forward, Map_Ptr); Report.Failed("Pattern_Error not raised by Index w/map ptr"); exception when Ada.Strings.Pattern_Error => null; -- OK, expected exception. when others => Report.Failed ("Incorrect exception raised by Index w/map ptr, null pattern"); end; -- Function Index -- Using the version of Index testing wide character set membership, -- check combinations of forward/backward, inside/outside parameter -- configurations. if ASF.Index(Source => Source_String1, -- "abcde" Set => CD_Set, Test => Ada.Strings.Inside, Going => Ada.Strings.Forward) /= 3 or -- 'c' at pos 3. ASF.Index(Source_String6, -- "abcdefabcdef" CD_Set, Ada.Strings.Outside, Ada.Strings.Backward) /= 12 or -- 'f' at position 12 ASF.Index(Source_String6, -- "abcdefabcdef" CD_Set, Ada.Strings.Inside, Ada.Strings.Backward) /= 10 or -- 'd' at position 10 ASF.Index("cdcdcdcdacdcdcdcd", CD_Set, Ada.Strings.Outside, Ada.Strings.Forward) /= 9 -- 'a' at position 9 then Report.Failed("Incorrect result from function Index for sets - 1"); end if; -- Additional interesting uses/combinations using Index for sets. if ASF.Index("cd", -- same size, str-set CD_Set, Ada.Strings.Inside, Ada.Strings.Forward) /= 1 or -- 'c' at position 1 ASF.Index("abcd", -- same size, str-set, Maps.To_Set("efgh"), -- different contents. Ada.Strings.Outside, Ada.Strings.Forward) /= 1 or ASF.Index("abccd", -- set > Wide_String Maps.To_Set("acegik"), Ada.Strings.Inside, Ada.Strings.Backward) /= 4 or -- 'c' at position 4 ASF.Index("abcde", Maps.Null_Set) /= 0 or ASF.Index("", -- Null string. CD_Set) /= 0 or ASF.Index("abc ab", -- blank included Maps.To_Set("e "), -- in Wide_String and Ada.Strings.Inside, -- set. Ada.Strings.Backward) /= 4 -- blank in Wide_Str. then Report.Failed("Incorrect result from function Index for sets - 2"); end if; -- Function Index_Non_Blank. -- (Other usage examples of this function found in CXA4013-14.) if ASF.Index_Non_Blank(Source => Source_String4, -- "abcdefghij " Going => Ada.Strings.Backward) /= 10 or ASF.Index_Non_Blank("abc def ghi jkl ", Ada.Strings.Backward) /= 15 or ASF.Index_Non_Blank(" abcdef") /= 3 or ASF.Index_Non_Blank(" ") /= 0 then Report.Failed("Incorrect result from Index_Non_Blank"); end if; -- Function Count -- (Other usage examples of this function found in CXA4013-14.) if ASF.Count("abababa", "aba") /= 2 or ASF.Count("abababa", "ab" ) /= 3 or ASF.Count("babababa", "ab") /= 3 or ASF.Count("abaabaaba", "aba") /= 3 or ASF.Count("xxxxxxxxxxxxxxxxxxxy", "xy") /= 1 or ASF.Count("xxxxxxxxxxxxxxxxxxxx", "x") /= 20 then Report.Failed("Incorrect result from Function Count"); end if; -- Determine the number of slices of Source that when mapped to a -- non-identity map, match the pattern Wide_String. Slice_Count := ASF.Count(Source_String6, -- "abcdefabcdef" "xy", CD_to_XY_Map); -- maps 'c' to 'x', 'd' to 'y' if Slice_Count /= 2 then -- two slices "xy" in "mapped" Source_String6 Report.Failed("Incorrect result from Count with non-identity map"); end if; -- If the pattern supplied to Function Count is the null Wide_String, -- then Pattern_Error is propagated. declare The_Null_Wide_String : constant Wide_String := ""; begin Slice_Count := ASF.Count(Source_String6, The_Null_Wide_String); Report.Failed("Pattern_Error not raised by Function Count"); exception when Ada.Strings.Pattern_Error => null; -- OK when others => Report.Failed("Incorrect exception from Count with null pattern"); end; -- Function Count -- Use the version of Count that takes a Wide_Character_Mapping_Function -- value as the basis of its source mapping. if ASF.Count("akakaka", "zqz", Map_Ptr) /= 2 or ASF.Count("akakaka", "qz", Map_Ptr) /= 3 or ASF.Count("kakakaka", "q", Map_Ptr) /= 4 or ASF.Count("zzqaakzaqzzk", "zzq", Map_Ptr) /= 4 or ASF.Count(" ", "z", Map_Ptr) /= 0 or ASF.Count("", "qz", Map_Ptr) /= 0 or ASF.Count("abbababab", "zq", Map_Ptr) /= 0 or ASF.Count("aaaaaaaaaaaaaaaaaakk", "zqq", Map_Ptr) /= 1 or ASF.Count("azaazaazzzaaaaazzzza", "z", Map_Ptr) /= 20 then Report.Failed("Incorrect result from Function Count w/map ptr"); end if; -- If the pattern supplied to Function Count is a null Wide_String, -- then Pattern_Error is propagated. declare The_Null_Wide_String : constant Wide_String := ""; begin Slice_Count := ASF.Count(Source_String6, The_Null_Wide_String, Map_Ptr); Report.Failed ("Pattern_Error not raised by Function Count w/map ptr"); exception when Ada.Strings.Pattern_Error => null; -- OK when others => Report.Failed ("Incorrect exception from Count w/map ptr, null pattern"); end; -- Function Count returning the number of characters in a particular -- set that are found in source Wide_String. if ASF.Count(Source_String6, CD_Set) /= 4 or -- 2 'c' and 'd' chars. ASF.Count("cddaccdaccdd", CD_Set) /= 10 then Report.Failed("Incorrect result from Count with set"); end if; -- Function Find_Token. -- (Other usage examples of this function found in CXA4013-14.) ASF.Find_Token(Source => Source_String6, -- First slice with no Set => ABCD_Set, -- 'a', 'b', 'c', or 'd' Test => Ada.Strings.Outside, -- is "ef" at 5..6. First => Slice_Start, Last => Slice_End); if Slice_Start /= 5 or Slice_End /= 6 then Report.Failed("Incorrect result from Find_Token - 1"); end if; -- If no appropriate slice is contained by the source Wide_String, -- then the value returned in Last is zero, and the value in First is -- Source'First. ASF.Find_Token(Source_String6, -- "abcdefabcdef" A_to_F_Set, -- Set of characters 'a' thru 'f'. Ada.Strings.Outside, -- No characters outside this set. Slice_Start, Slice_End); if Slice_Start /= Source_String6'First or Slice_End /= 0 then Report.Failed("Incorrect result from Find_Token - 2"); end if; -- Additional testing of Find_Token. ASF.Find_Token("eabcdabcddcab", ABCD_Set, Ada.Strings.Inside, Slice_Start, Slice_End); if Slice_Start /= 2 or Slice_End /= 13 then Report.Failed("Incorrect result from Find_Token - 3"); end if; ASF.Find_Token("efghijklabcdabcd", ABCD_Set, Ada.Strings.Outside, Slice_Start, Slice_End); if Slice_Start /= 1 or Slice_End /= 8 then Report.Failed("Incorrect result from Find_Token - 4"); end if; ASF.Find_Token("abcdefgabcdabcd", ABCD_Set, Ada.Strings.Outside, Slice_Start, Slice_End); if Slice_Start /= 5 or Slice_End /= 7 then Report.Failed("Incorrect result from Find_Token - 5"); end if; ASF.Find_Token("abcdcbabcdcba", ABCD_Set, Ada.Strings.Inside, Slice_Start, Slice_End); if Slice_Start /= 1 or Slice_End /= 13 then Report.Failed("Incorrect result from Find_Token - 6"); end if; exception when others => Report.Failed("Exception raised in Test_Block"); end Test_Block; Report.Result;end CXA4015;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?