From 087e4ed6cc9da9cfca1a107058905446ff474bd1 Mon Sep 17 00:00:00 2001 From: nagachika Date: Fri, 18 Oct 2024 13:03:48 +0900 Subject: merge revision(s) 35e124832e29b65c84d4e0e4e434616859f9bdf5: [Backport #20755] [Bug #20755] Frozen string should not be writable via IO::Buffer --- test/ruby/test_io_buffer.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index f3eb37a513..1c76403b2d 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -221,6 +221,31 @@ class TestIOBuffer < Test::Unit::TestCase assert_equal "Hello World", hello end + def test_transfer + hello = %w"Hello World".join(" ") + buffer = IO::Buffer.for(hello) + transferred = buffer.transfer + assert_equal "Hello World", transferred.get_string + assert_predicate buffer, :null? + assert_raise IO::Buffer::AccessError do + transferred.set_string("Goodbye") + end + assert_equal "Hello World", hello + end + + def test_transfer_in_block + hello = %w"Hello World".join(" ") + buffer = IO::Buffer.for(hello, &:transfer) + assert_equal "Hello World", buffer.get_string + buffer.set_string("Ciao!") + assert_equal "Ciao! World", hello + hello.freeze + assert_raise IO::Buffer::AccessError do + buffer.set_string("Hola") + end + assert_equal "Ciao! World", hello + end + def test_locked buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED) -- cgit v1.2.3