From 48098b30ada79323a8500122fe02ea91d925ae60 Mon Sep 17 00:00:00 2001 From: Vadim Godunko Date: Tue, 19 Nov 2024 10:12:27 +0000 Subject: [PATCH] Revert "Merge branch 'revert-6703ac0e' into 'master'" This reverts merge request !344 --- Makefile | 1 - gnat/tests/vss_text_tests.gpr | 1 - ...lementation-text_handlers-utf8-dynamic.adb | 4 +- ...plementation-text_handlers-utf8-static.adb | 4 +- ...g_slice.adb => test_string-test_slice.adb} | 38 ++++++++++++++++--- testsuite/text/test_string.adb | 9 +++++ 6 files changed, 48 insertions(+), 9 deletions(-) rename testsuite/text/{test_string_slice.adb => test_string-test_slice.adb} (78%) diff --git a/Makefile b/Makefile index 2ca4a14f..222e5500 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,6 @@ check_text: .objs/tests/test_string_hash .objs/tests/test_string_insert .objs/tests/test_string_buffer - .objs/tests/test_string_slice .objs/tests/test_string_split .objs/tests/test_string_split_lines .objs/tests/test_string diff --git a/gnat/tests/vss_text_tests.gpr b/gnat/tests/vss_text_tests.gpr index e9655d03..3e6b41fa 100644 --- a/gnat/tests/vss_text_tests.gpr +++ b/gnat/tests/vss_text_tests.gpr @@ -33,7 +33,6 @@ project VSS_Text_Tests is "test_string_hash", "test_string_insert", "test_string_buffer", - "test_string_slice", "test_string_split", "test_string_split_lines", "test_string_template", diff --git a/source/text/implementation/vss-implementation-text_handlers-utf8-dynamic.adb b/source/text/implementation/vss-implementation-text_handlers-utf8-dynamic.adb index 5f71b3f7..06f61adb 100644 --- a/source/text/implementation/vss-implementation-text_handlers-utf8-dynamic.adb +++ b/source/text/implementation/vss-implementation-text_handlers-utf8-dynamic.adb @@ -576,7 +576,9 @@ package body VSS.Implementation.Text_Handlers.UTF8.Dynamic is return; end if; - Unchecked_Forward (Self.Pointer.Storage, After); + if To.Index <= Self.Length then + Unchecked_Forward (Self.Pointer.Storage, After); + end if; Size := After.UTF8_Offset - From.UTF8_Offset; Length := After.Index - From.Index; diff --git a/source/text/implementation/vss-implementation-text_handlers-utf8-static.adb b/source/text/implementation/vss-implementation-text_handlers-utf8-static.adb index 58f6664e..1e4a5e83 100644 --- a/source/text/implementation/vss-implementation-text_handlers-utf8-static.adb +++ b/source/text/implementation/vss-implementation-text_handlers-utf8-static.adb @@ -515,7 +515,9 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is return; end if; - Unchecked_Forward (Self.Storage, After); + if To.Index <= Self.Length then + Unchecked_Forward (Self.Storage, After); + end if; Size := After.UTF8_Offset - From.UTF8_Offset; Length := After.Index - From.Index; diff --git a/testsuite/text/test_string_slice.adb b/testsuite/text/test_string-test_slice.adb similarity index 78% rename from testsuite/text/test_string_slice.adb rename to testsuite/text/test_string-test_slice.adb index e5620a9a..f18ffbb6 100644 --- a/testsuite/text/test_string_slice.adb +++ b/testsuite/text/test_string-test_slice.adb @@ -1,5 +1,5 @@ -- --- Copyright (C) 2021-2022, AdaCore +-- Copyright (C) 2021-2024, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -- @@ -14,9 +14,8 @@ with VSS.Strings.Character_Iterators; with VSS.Strings.Line_Iterators; -with Test_Support; - -procedure Test_String_Slice is +separate (Test_String) +procedure Test_Slice is use type VSS.Strings.Virtual_String; S : constant VSS.Strings.Virtual_String := @@ -157,4 +156,33 @@ begin R := S1.Slice (JLV, JLV); Test_Support.Assert (R.Is_Null); end; -end Test_String_Slice; + + -- Slice of string with last marker pointing to end of string. + -- + -- It was reported under eng/ide/VSS#256 + + declare + use type VSS.Strings.Character_Count; + + SS : VSS.Strings.Virtual_String := "body "; + -- Static storage + SR : VSS.Strings.Virtual_String := "package body "; + -- Reported case: static storage of max size on 64bit platform + SD : VSS.Strings.Virtual_String := "package body Name "; + -- Dynamic storage + R : VSS.Strings.Virtual_String; + + begin + R := SS.Slice (SS.At_First_Character, SS.After_Last_Character); + Test_Support.Assert (R.Character_Length = SS.Character_Length); + Test_Support.Assert (R = SS); + + R := SR.Slice (SR.At_First_Character, SR.After_Last_Character); + Test_Support.Assert (R.Character_Length = SR.Character_Length); + Test_Support.Assert (R = SR); + + R := SD.Slice (SD.At_First_Character, SD.After_Last_Character); + Test_Support.Assert (R.Character_Length = SD.Character_Length); + Test_Support.Assert (R = SD); + end; +end Test_Slice; diff --git a/testsuite/text/test_string.adb b/testsuite/text/test_string.adb index f1382fc3..76a21ac2 100644 --- a/testsuite/text/test_string.adb +++ b/testsuite/text/test_string.adb @@ -5,6 +5,7 @@ -- with VSS.Strings.Character_Iterators; +with VSS.Strings.Line_Iterators; with VSS.String_Vectors; with Test_Support; @@ -21,6 +22,7 @@ procedure Test_String is procedure Test_Prepend; procedure Test_Put_Image; procedure Test_Replace; + procedure Test_Slice; procedure Test_Tail; procedure Test_V705_011; @@ -154,6 +156,12 @@ procedure Test_String is end; end Test_Replace; + ---------------- + -- Test_Slice -- + ---------------- + + procedure Test_Slice is separate; + --------------- -- Test_Tail -- --------------- @@ -229,6 +237,7 @@ procedure Test_String is Test_Support.Run_Testcase (Test_Prepend'Access, "Prepend"); Test_Support.Run_Testcase (Test_Put_Image'Access, "Put_Image"); Test_Support.Run_Testcase (Test_Replace'Access, "Replace"); + Test_Support.Run_Testcase (Test_Slice'Access, "Slice"); Test_Support.Run_Testcase (Test_Tail'Access, "Tail"); Test_Support.Run_Testcase (Test_V705_011'Access, "V705_011 TN");