summaryrefslogtreecommitdiff
path: root/test/ruby/test_io_buffer.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-09-30 16:24:03 +0900
committerNobuyoshi Nakada <[email protected]>2024-09-30 20:39:14 +0900
commit637067440f74043c6d79fc649ab8acf1afea25a5 (patch)
treea95e6961ba6754b250dbfcc86132f7f72823b7d3 /test/ruby/test_io_buffer.rb
parentb93c51c114c2b3c8f9845f3a7bd2c936baf0996d (diff)
[Bug #20752] Slice of readonly `IO::Buffer` also should be readonly
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11735
Diffstat (limited to 'test/ruby/test_io_buffer.rb')
-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 7a58ec0c5a..7087a2b957 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -236,6 +236,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)