Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 21, 2024
1 parent f755edc commit f9ed1be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/protocol/http/body/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,18 @@ def read_partial(length = nil, buffer = nil)
buffer.replace(@buffer)
else
buffer = @buffer
@buffer = nil
end
@buffer = nil
else
chunk = read_next

if buffer and chunk
buffer.replace(chunk)
if chunk = read_next
if buffer
buffer.replace(chunk)
else
buffer = chunk
end
else
buffer = chunk
buffer&.clear
buffer = nil
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/protocol/http/body/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@
expect(stream.read_partial(2)).to be == "d"
expect(stream.read_partial(2)).to be == nil
end

it "can read partial input with buffer" do
buffer = String.new
expect(stream.read_partial(2, buffer)).to be == "He"
expect(buffer).to be == "He"
expect(stream.read_partial(2, buffer)).to be == "ll"
expect(buffer).to be == "ll"
expect(stream.read_partial(2, buffer)).to be == "o"
expect(buffer).to be == "o"
expect(stream.read_partial(2, buffer)).to be == "Wo"
expect(buffer).to be == "Wo"
expect(stream.read_partial(2, buffer)).to be == "rl"
expect(buffer).to be == "rl"
expect(stream.read_partial(2, buffer)).to be == "d"
expect(buffer).to be == "d"
expect(stream.read_partial(2, buffer)).to be == nil
expect(buffer).to be == ""
end
end

with '#readpartial' do
Expand Down

0 comments on commit f9ed1be

Please sign in to comment.