diff options
| author | nagachika <nagachika@ruby-lang.org> | 2024-10-18 13:03:48 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2024-10-18 13:57:08 +0900 |
| commit | 087e4ed6cc9da9cfca1a107058905446ff474bd1 (patch) | |
| tree | f373e3b5c6f9d955b43f73c96fc082116a1e4ea9 /test | |
| parent | d85516eab59f932d65283572d0b9090005f60c20 (diff) | |
merge revision(s) 35e124832e29b65c84d4e0e4e434616859f9bdf5: [Backport #20755]
[Bug #20755] Frozen string should not be writable via IO::Buffer
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_io_buffer.rb | 25 |
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) |
