summaryrefslogtreecommitdiff
path: root/test/ruby/test_io_buffer.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-09-30 22:49:09 +0900
committerNobuyoshi Nakada <[email protected]>2024-10-01 18:46:35 +0900
commit35e124832e29b65c84d4e0e4e434616859f9bdf5 (patch)
tree4277cdab7ee595540b686afb971a1f17248782fa /test/ruby/test_io_buffer.rb
parent3ebc85e240c64849e8645ae9b6242abbd1a2b63a (diff)
[Bug #20755] Frozen string should not be writable via IO::Buffer
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11738
Diffstat (limited to 'test/ruby/test_io_buffer.rb')
-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 7087a2b957..98cf45d0c3 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -248,6 +248,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)