diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2023-05-24 10:17:35 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 10:17:35 +0900 |
commit | 135a0d26a11cf0d0825e4f80e00e2b430555d831 (patch) | |
tree | d110f277f945e0dc819ed7d86b2a0d57c73a2265 /test | |
parent | 12dfd9d1c980d17d8a0ea10bccb9cd7eca21b568 (diff) |
Improvements to `IO::Buffer` `read`/`write`/`pread`/`pwrite`. (#7826)
- Fix IO::Buffer `read`/`write` to use a minimum length.
Notes
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_io_buffer.rb | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index b9d52d83ce..75ec4016fa 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -361,17 +361,38 @@ class TestIOBuffer < Test::Unit::TestCase input.close end - def test_read + def hello_world_tempfile io = Tempfile.new io.write("Hello World") io.seek(0) - buffer = IO::Buffer.new(128) - buffer.read(io, 5) - - assert_equal "Hello", buffer.get_string(0, 5) + yield io ensure - io.close! if io + io&.close! + end + + def test_read + hello_world_tempfile do |io| + buffer = IO::Buffer.new(128) + buffer.read(io) + assert_equal "Hello", buffer.get_string(0, 5) + end + end + + def test_read_with_with_length + hello_world_tempfile do |io| + buffer = IO::Buffer.new(128) + buffer.read(io, 5) + assert_equal "Hello", buffer.get_string(0, 5) + end + end + + def test_read_with_with_offset + hello_world_tempfile do |io| + buffer = IO::Buffer.new(128) + buffer.read(io, nil, 6) + assert_equal "Hello", buffer.get_string(6, 5) + end end def test_write @@ -379,7 +400,7 @@ class TestIOBuffer < Test::Unit::TestCase buffer = IO::Buffer.new(128) buffer.set_string("Hello") - buffer.write(io, 5) + buffer.write(io) io.seek(0) assert_equal "Hello", io.read(5) |