summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2023-09-30 13:51:18 +0900
committernagachika <nagachika@ruby-lang.org>2023-09-30 13:51:18 +0900
commitddbab4f837460f070942e8127de9a9f1b9868fff (patch)
treeedfc27866027033b4c319dbd0b1848762acc26e0 /test
parent128d8728d39c2da21e5433c7af169f73e18fd133 (diff)
merge revision(s) 6b66b5fdedb2c9a9ee48e290d57ca7f8d55e01a2: [Backport #19902]
[Bug #19902] Update the coderange regarding the changed region --- ext/-test-/string/set_len.c | 10 ++++++++++ string.c | 27 +++++++++++++++++++++++++++ test/-ext-/string/test_set_len.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+)
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/string/test_set_len.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/-ext-/string/test_set_len.rb b/test/-ext-/string/test_set_len.rb
index 67ba961194..e3eff75d9b 100644
--- a/test/-ext-/string/test_set_len.rb
+++ b/test/-ext-/string/test_set_len.rb
@@ -34,4 +34,33 @@ class Test_StrSetLen < Test::Unit::TestCase
assert_equal 128, Bug::String.capacity(str)
assert_equal 127, str.set_len(127).bytesize, bug12757
end
+
+ def test_coderange_after_append
+ u = -"\u3042"
+ str = Bug::String.new(encoding: Encoding::UTF_8)
+ bsize = u.bytesize
+ str.append(u)
+ assert_equal 0, str.bytesize
+ str.set_len(bsize)
+ assert_equal bsize, str.bytesize
+ assert_predicate str, :valid_encoding?
+ assert_not_predicate str, :ascii_only?
+ assert_equal u, str
+ end
+
+ def test_coderange_after_trunc
+ u = -"\u3042"
+ bsize = u.bytesize
+ str = Bug::String.new(u)
+ str.set_len(bsize - 1)
+ assert_equal bsize - 1, str.bytesize
+ assert_not_predicate str, :valid_encoding?
+ assert_not_predicate str, :ascii_only?
+ str.append(u.byteslice(-1))
+ str.set_len(bsize)
+ assert_equal bsize, str.bytesize
+ assert_predicate str, :valid_encoding?
+ assert_not_predicate str, :ascii_only?
+ assert_equal u, str
+ end
end