Skip to content

Commit

Permalink
Fix IO::Memory#gets_to_end to consume the IO
Browse files Browse the repository at this point in the history
  • Loading branch information
jhass authored and asterite committed May 20, 2017
1 parent 6dffcff commit b2def93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/io/memory_spec.cr
Expand Up @@ -331,6 +331,12 @@ describe IO::Memory do
end
end

it "consumes with gets_to_end" do
io = IO::Memory.new("hello world")
io.gets_to_end.should eq("hello world")
io.gets_to_end.should eq("")
end

it "peeks" do
str = "hello world"
io = IO::Memory.new(str)
Expand Down
4 changes: 3 additions & 1 deletion src/io/memory.cr
Expand Up @@ -225,7 +225,9 @@ class IO::Memory
if pos == @bytesize
""
else
String.new(@buffer + @pos, @bytesize - @pos)
String.new(@buffer + @pos, @bytesize - @pos).tap {
@pos = @bytesize
}
end
end

Expand Down

0 comments on commit b2def93

Please sign in to comment.