Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eof check for streaming parser #321

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Return `true` if there is a current byte, and `false` if all bytes have been
exausted.
"""
@inline hasmore(ps::MemoryParserState) = ps.s ≤ length(ps)
@inline hasmore(ps::StreamingParserState) = true # no more now ≠ no more ever
@inline hasmore(ps::StreamingParserState) = !ps.used || !eof(ps.io)

"""
Remove as many whitespace bytes as possible from the `ParserState` starting from
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ include("json-samples.jl")
@test JSON.parse("1") == 1
@test JSON.parse("1.5") == 1.5
@test JSON.parse("[true]") == [true]

# test for parsing single values in streams
@test JSON.parse(IOBuffer("123")) == 123
@test JSON.parse(IOBuffer("1.5")) == 1.5
end
end

Expand Down