Index: tests/natools-string_slice_tests.adb ================================================================== --- tests/natools-string_slice_tests.adb +++ tests/natools-string_slice_tests.adb @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013, Natacha Porté -- +-- Copyright (c) 2013-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -78,10 +78,11 @@ Test_Incoming_Range (Report); Test_Invalid_Extensions (Report); Test_Null_Slice (Report); Test_Outgoing_Range (Report); Test_Subslices (Report); + Test_New_Slice (Report); end Slice_Tests; ---------------------- @@ -456,10 +457,80 @@ end if; exception when Error : others => Report.Report_Exception (Name, Error); end Test_Is_Subrange; + + procedure Test_New_Slice (Report : in out NT.Reporter'Class) is + Name : constant String := "Callback-based constructor"; + First : constant Positive := 42; + Last : constant Natural := First + Name'Length - 1; + Result : Boolean := True; + + procedure Initialize (S : out String); + + procedure Initialize (S : out String) is + begin + S := Name; + end Initialize; + begin + declare + Slice : constant String_Slices.Slice + := String_Slices.New_Slice (First, Last, Initialize'Access); + begin + if Slice.First /= First then + if Result then + Report.Item (Name, NT.Fail); + end if; + + Report.Info ("Incorrect value" + & Integer'Image (Slice.First) & " for Slice.First, expected" + & Integer'Image (First)); + Result := False; + end if; + + if Slice.Last /= Last then + if Result then + Report.Item (Name, NT.Fail); + end if; + + Report.Info ("Incorrect value" + & Integer'Image (Slice.Last) & " for Slice.Last, expected" + & Integer'Image (Last)); + Result := False; + end if; + + if Slice.Length /= Name'Length then + if Result then + Report.Item (Name, NT.Fail); + end if; + + Report.Info ("Incorrect value" + & Integer'Image (Slice.Length) & " for Slice.Length, expected" + & Integer'Image (Name'Length)); + Result := False; + end if; + + if Slice.To_String /= Name then + if Result then + Report.Item (Name, NT.Fail); + end if; + + Report.Info ("Incorrect string """ + & Integer'Image (Slice.Length) & """ in Slice, expected """ + & Name & '"'); + Result := False; + end if; + end; + + if Result then + Report.Item (Name, NT.Success); + end if; + exception + when Error : others => Report.Report_Exception (Name, Error); + end Test_New_Slice; + procedure Test_Null_Slice (Report : in out NT.Reporter'Class) is procedure Check_Null (S : in String); Name : constant String := "Null slice to empty string"; Index: tests/natools-string_slice_tests.ads ================================================================== --- tests/natools-string_slice_tests.ads +++ tests/natools-string_slice_tests.ads @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013, Natacha Porté -- +-- Copyright (c) 2013-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -38,11 +38,12 @@ procedure Test_Conversions (Report : in out NT.Reporter'Class); procedure Test_Extensions (Report : in out NT.Reporter'Class); procedure Test_Incoming_Range (Report : in out NT.Reporter'Class); procedure Test_Invalid_Extensions (Report : in out NT.Reporter'Class); procedure Test_Invalid_Subslices (Report : in out NT.Reporter'Class); + procedure Test_New_Slice (Report : in out NT.Reporter'Class); procedure Test_Null_Slice (Report : in out NT.Reporter'Class); procedure Test_Outgoing_Range (Report : in out NT.Reporter'Class); procedure Test_Slice_Relations (Report : in out NT.Reporter'Class); procedure Test_Subslices (Report : in out NT.Reporter'Class); end Natools.String_Slice_Tests;