1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Rework implementation of IO::Buffer.for(string) to use string locking.

This commit is contained in:
Samuel Williams 2021-10-22 15:05:00 +13:00
parent 98b442e013
commit c833ece5f7
Notes: git 2021-11-12 12:46:30 +09:00
2 changed files with 39 additions and 0 deletions

View file

@ -62,6 +62,25 @@ class TestIOBuffer < Test::Unit::TestCase
assert_include buffer.to_str, "Hello World"
end
def test_string_mapped
string = "Hello World"
buffer = IO::Buffer.for(string)
# Cannot modify string as it's locked by the buffer:
assert_raise RuntimeError do
string[0] = "h"
end
buffer.set(: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
end
def test_resize
buffer = IO::Buffer.new(1024, IO::Buffer::MAPPED)
buffer.resize(2048, 0)