Add IO::Buffer
tests for read and write with length & offset. (#11779)
This commit is contained in:
parent
218445bb1f
commit
cd96af2cb8
Notes:
git
2024-10-03 12:29:40 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user