📄 cxa4032.a
字号:
-- CXA4032.A---- Grant of Unlimited Rights---- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein.-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so.---- DISCLAIMER---- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A-- PARTICULAR PURPOSE OF SAID MATERIAL.--*---- OBJECTIVE:-- Check that procedures defined in package Ada.Strings.Unbounded-- are available, and that they produce correct results. Specifically, -- check the procedures Replace_Slice, Insert, Overwrite, Delete,-- Trim (2 versions), Head, and Tail.-- -- TEST DESCRIPTION:-- This test demonstrates the uses of many of the procedures defined-- in package Ada.Strings.Unbounded for use with unbounded strings.-- The test simulates how unbounded strings could be processed in a-- user environment, using the procedures provided in this package.---- This test, when taken in conjunction with tests CXA4010, CXA4011,-- CXA4030, and CXA4031 will constitute a test of all the functionality -- contained in package Ada.Strings.Unbounded. This test uses a variety -- of the procedures defined in the unbounded string package in ways -- typical of common usage.-- -- -- CHANGE HISTORY:-- 02 Mar 95 SAIC Initial prerelease version.----!with Report;with Ada.Strings;with Ada.Strings.Maps;with Ada.Strings.Maps.Constants;with Ada.Strings.Unbounded;procedure CXA4032 isbegin Report.Test ("CXA4032", "Check that the subprograms defined in " & "package Ada.Strings.Unbounded are available, " & "and that they produce correct results"); Test_Block: declare package Unb renames Ada.Strings.Unbounded; use Unb; use Ada.Strings; TC_Null_String : constant String := ""; TC_String_5 : String(1..5) := "ABCDE"; TC_Unb_String : Unb.Unbounded_String := Unb.To_Unbounded_String("Test String"); begin -- Procedure Replace_Slice begin -- Low > Source'Last+1 Unb.Replace_Slice(Source => TC_Unb_String, Low => Unb.Length(TC_Unb_String) + 2, High => Unb.Length(TC_Unb_String), By => TC_String_5); Report.Failed("Index_Error not raised by Replace_Slice when Low " & "> Source'Last+1"); exception when Index_Error => null; -- OK, expected exception. when others => Report.Failed("Unexpected exception raised by Replace_Slice" & "when Low > Source'Last+1"); end; -- High >= Low TC_Unb_String := Unb.To_Unbounded_String("Test String"); Unb.Replace_Slice(TC_Unb_String, 5, 5, TC_String_5); if TC_Unb_String /= Unb.To_Unbounded_String("TestABCDEString") then Report.Failed("Incorrect results from Replace_Slice - 1"); end if; Unb.Replace_Slice(TC_Unb_String, 1, 4, TC_String_5); if TC_Unb_String /= Unb.To_Unbounded_String("ABCDEABCDEString") then Report.Failed("Incorrect results from Replace_Slice - 2"); end if; Unb.Replace_Slice(TC_Unb_String, 11, Unb.Length(TC_Unb_String), TC_Null_String); if TC_Unb_String /= Unb.To_Unbounded_String("ABCDEABCDE") then Report.Failed("Incorrect results from Replace_Slice - 3"); end if; -- High < Low Unb.Replace_Slice(TC_Unb_String, Low => 4, High => 1, By => "xxx"); if TC_Unb_String /= Unb.To_Unbounded_String("ABCxxxDEABCDE") then Report.Failed("Incorrect results from Replace_Slice - 4"); end if; Unb.Replace_Slice(TC_Unb_String, Low => 1, High => 0, By => "yyy"); if TC_Unb_String /= Unb.To_Unbounded_String("yyyABCxxxDEABCDE") then Report.Failed("Incorrect results from Replace_Slice - 5"); end if; Unb.Replace_Slice(TC_Unb_String, Unb.Length(TC_Unb_String) + 1, Unb.Length(TC_Unb_String), By => "zzz"); if TC_Unb_String /= Unb.To_Unbounded_String("yyyABCxxxDEABCDEzzz") then Report.Failed("Incorrect results from Replace_Slice - 6"); end if; -- Procedure Insert TC_Unb_String := Unb.To_Unbounded_String("Test String"); begin -- Before not in Source'First..Source'Last + 1 Unb.Insert(Source => TC_Unb_String, Before => Unb.Length(TC_Unb_String) + 2, New_Item => TC_String_5); Report.Failed("Index_Error not raised by Insert when Before " & "not in the range Source'First..Source'Last+1"); exception when Index_Error => null; -- OK, expected exception. when others => Report.Failed ("Unexpected exception raised by Insert when Before not in " & "the range Source'First..Source'Last+1"); end; Unb.Insert(TC_Unb_String, 1, "**"); if TC_Unb_String /= Unb.To_Unbounded_String("**Test String") then Report.Failed("Incorrect results from Insert - 1"); end if; Unb.Insert(TC_Unb_String, Unb.Length(TC_Unb_String)+1, "**"); if TC_Unb_String /= Unb.To_Unbounded_String("**Test String**") then Report.Failed("Incorrect results from Insert - 2"); end if; Unb.Insert(TC_Unb_String, 8, "---"); if TC_Unb_String /= Unb.To_Unbounded_String("**Test ---String**") then Report.Failed("Incorrect results from Insert - 3"); end if; Unb.Insert(TC_Unb_String, 3, TC_Null_String); if TC_Unb_String /= Unb.To_Unbounded_String("**Test ---String**") then Report.Failed("Incorrect results from Insert - 4"); end if; -- Procedure Overwrite begin -- Position not in Source'First..Source'Last + 1 Unb.Overwrite(Source => TC_Unb_String, Position => Unb.Length(TC_Unb_String) + 2, New_Item => TC_String_5); Report.Failed("Index_Error not raised by Overwrite when Position " & "not in the range Source'First..Source'Last+1"); exception when Index_Error => null; -- OK, expected exception. when others => Report.Failed ("Unexpected exception raised by Overwrite when Position not " & "in the range Source'First..Source'Last+1"); end; TC_Unb_String := Unb.To_Unbounded_String("Test String"); Unb.Overwrite(Source => TC_Unb_String, Position => 1, New_Item => "XXXX"); if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String") then Report.Failed("Incorrect results from Overwrite - 1"); end if; Unb.Overwrite(TC_Unb_String, Unb.Length(TC_Unb_String)+1, "**"); if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String**") then Report.Failed("Incorrect results from Overwrite - 2"); end if; Unb.Overwrite(TC_Unb_String, 3, TC_Null_String); if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String**") then Report.Failed("Incorrect results from Overwrite - 3"); end if; Unb.Overwrite(TC_Unb_String, 1, "abcdefghijklmn"); if TC_Unb_String /= Unb.To_Unbounded_String("abcdefghijklmn") then Report.Failed("Incorrect results from Overwrite - 4"); end if;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -