summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2024-10-18 11:30:05 +0900
committernagachika <nagachika@ruby-lang.org>2024-10-18 11:30:05 +0900
commit5777fe5ab57d6479326bdb21ef9a6b88ea1516dc (patch)
tree867e9c9808d95caff34c983aeda7a84eee6d43b7 /test/ruby
parent18074c508105244552678cf6afd4b23304cb4c8f (diff)
merge revision(s) 637067440f74043c6d79fc649ab8acf1afea25a5: [Backport #20752]
[Bug #20752] Slice of readonly `IO::Buffer` also should be readonly
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_io_buffer.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb
index ae3fba2e41..f3eb37a513 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -209,6 +209,18 @@ class TestIOBuffer < Test::Unit::TestCase
end
end
+ def test_slice_readonly
+ hello = %w"Hello World".join(" ").freeze
+ buffer = IO::Buffer.for(hello)
+ slice = buffer.slice
+ assert_predicate slice, :readonly?
+ assert_raise IO::Buffer::AccessError do
+ # This breaks the literal in string pool and many other tests in this file.
+ slice.set_string("Adios", 0, 5)
+ end
+ assert_equal "Hello World", hello
+ end
+
def test_locked
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)