diff options
author | Samuel Williams <[email protected]> | 2024-10-04 01:29:16 +1300 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-03 12:29:16 +0000 |
commit | cd96af2cb88a0b98add14eacf0005a8bee505d5d (patch) | |
tree | 49c6aca8ceebb90be78a02ddf7c0a98bf473109c /test/ruby/test_io_buffer.rb | |
parent | 218445bb1fbda6b215b42e6149da672d330a7042 (diff) |
Add `IO::Buffer` tests for read and write with length & offset. (#11779)
Notes
Notes:
Merged-By: ioquatix <[email protected]>
Diffstat (limited to 'test/ruby/test_io_buffer.rb')
-rw-r--r-- | test/ruby/test_io_buffer.rb | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index 98cf45d0c3..178ed05003 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -450,9 +450,11 @@ class TestIOBuffer < Test::Unit::TestCase input.close end - def hello_world_tempfile + def hello_world_tempfile(repeats = 1) io = Tempfile.new - io.write("Hello World") + repeats.times do + io.write("Hello World") + end io.seek(0) yield io @@ -484,6 +486,15 @@ class TestIOBuffer < Test::Unit::TestCase end end + def test_read_with_length_and_offset + hello_world_tempfile(100) do |io| + buffer = IO::Buffer.new(1024) + # Only read 24 bytes from the file, as we are starting at offset 1000 in the buffer. + assert_equal 24, buffer.read(io, 0, 1000) + assert_equal "Hello World", buffer.get_string(1000, 11) + end + end + def test_write io = Tempfile.new @@ -497,6 +508,19 @@ class TestIOBuffer < Test::Unit::TestCase io.close! end + def test_write_with_length_and_offset + io = Tempfile.new + + buffer = IO::Buffer.new(5) + buffer.set_string("Hello") + buffer.write(io, 4, 1) + + io.seek(0) + assert_equal "ello", io.read(4) + ensure + io.close! + end + def test_pread io = Tempfile.new io.write("Hello World") |