Skip to content

Commit

Permalink
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/io/memory_spec.cr
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion src/io/memory.cr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b2def93

Please sign in to comment.