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:
parent
98b442e013
commit
c833ece5f7
Notes:
git
2021-11-12 12:46:30 +09:00
2 changed files with 39 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue