From 12ea98e8c8af0ed6778aad26e7ec5f95e2c239e5 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 4 Nov 2024 14:38:18 -0800 Subject: merge revision(s) 637067440f74043c6d79fc649ab8acf1afea25a5: [Backport #20752] [Bug #20752] Slice of readonly `IO::Buffer` also should be readonly --- test/ruby/test_io_buffer.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ruby') 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) -- cgit v1.2.3