summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2024-10-18 13:03:48 +0900
committernagachika <nagachika@ruby-lang.org>2024-10-18 13:57:08 +0900
commit087e4ed6cc9da9cfca1a107058905446ff474bd1 (patch)
treef373e3b5c6f9d955b43f73c96fc082116a1e4ea9 /test/ruby
parentd85516eab59f932d65283572d0b9090005f60c20 (diff)
merge revision(s) 35e124832e29b65c84d4e0e4e434616859f9bdf5: [Backport #20755]
[Bug #20755] Frozen string should not be writable via IO::Buffer
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_io_buffer.rb25
1 files changed, 25 insertions, 0 deletions
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)