diff options
author | nagachika <nagachika@ruby-lang.org> | 2022-09-04 16:24:57 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-09-04 16:24:57 +0900 |
commit | 882d4203f184ac93ac5c2c02c1e9f4b26cfad1db (patch) | |
tree | 55c8021e6996c970b1bb2b629ad02544b54ba1ba /test | |
parent | 6b8bf6ba5d1893b3c933c2de3ada1eb59a94b644 (diff) |
merge revision(s) ef525b012a709077ea2797e8642fae0b61234063,dc9a13abeef5a2b936fbb55edc112b8b382a05e7: [Backport #18775]
Explicit handling of frozen strings in `IO::Buffer#for`. (#5892)
---
io_buffer.c | 122 +++++++++++++++++++++++++++++++++++---------
test/ruby/test_io_buffer.rb | 36 +++++++------
2 files changed, 117 insertions(+), 41 deletions(-)
Fix rdoc of IO::Buffer [ci skip]
---
io_buffer.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_io_buffer.rb | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index 7e3b467ed5..e3f7021b26 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -88,30 +88,34 @@ class TestIOBuffer < Test::Unit::TestCase def test_string_mapped string = "Hello World" buffer = IO::Buffer.for(string) - refute buffer.readonly? - - # Cannot modify string as it's locked by the buffer: - assert_raise RuntimeError do - string[0] = "h" - end - - buffer.set_value(:U8, 0, "h".ord) - - # Buffer releases it's ownership of the string: - buffer.free - - assert_equal "hello World", string - string[0] = "H" - assert_equal "Hello World", string + assert buffer.readonly? end def test_string_mapped_frozen string = "Hello World".freeze buffer = IO::Buffer.for(string) - assert buffer.readonly? end + def test_string_mapped_mutable + string = "Hello World" + IO::Buffer.for(string) do |buffer| + refute buffer.readonly? + + # Cannot modify string as it's locked by the buffer: + assert_raise RuntimeError do + string[0] = "h" + end + + buffer.set_value(:U8, 0, "h".ord) + + # Buffer releases it's ownership of the string: + buffer.free + + assert_equal "hello World", string + end + end + def test_non_string not_string = Object.new |