From 968b49a434aaf7d4aa3c41cca4e00989b912ddbc Mon Sep 17 00:00:00 2001 From: Mark Wardle Date: Fri, 7 May 2021 08:12:05 -0600 Subject: [PATCH 1/2] Add eof check for streaming parser --- src/Parser.jl | 2 +- test/regression/issue314.jl | 2 ++ test/runtests.jl | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 test/regression/issue314.jl diff --git a/src/Parser.jl b/src/Parser.jl index 5b1f9d7..0a4eaf1 100644 --- a/src/Parser.jl +++ b/src/Parser.jl @@ -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 diff --git a/test/regression/issue314.jl b/test/regression/issue314.jl new file mode 100644 index 0000000..4ef1eda --- /dev/null +++ b/test/regression/issue314.jl @@ -0,0 +1,2 @@ +@test JSON.parse(IOBuffer("123")) == 123 +@test JSON.parse(IOBuffer("1.5")) == 1.5 diff --git a/test/runtests.jl b/test/runtests.jl index d585154..9e6107d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -80,7 +80,7 @@ end end @testset "Regression" begin - @testset "for issue #$i" for i in [21, 26, 57, 109, 152, 163] + @testset "for issue #$i" for i in [21, 26, 57, 109, 152, 163, 314] include("regression/issue$(lpad(string(i), 3, "0")).jl") end end From d88060e7628aad3944e3caa304d9ef1c0d92696f Mon Sep 17 00:00:00 2001 From: Mark Wardle Date: Fri, 7 May 2021 09:36:10 -0600 Subject: [PATCH 2/2] Move stream eof tests to miscellaneous section --- test/regression/issue314.jl | 2 -- test/runtests.jl | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 test/regression/issue314.jl diff --git a/test/regression/issue314.jl b/test/regression/issue314.jl deleted file mode 100644 index 4ef1eda..0000000 --- a/test/regression/issue314.jl +++ /dev/null @@ -1,2 +0,0 @@ -@test JSON.parse(IOBuffer("123")) == 123 -@test JSON.parse(IOBuffer("1.5")) == 1.5 diff --git a/test/runtests.jl b/test/runtests.jl index 9e6107d..0d950d0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -80,7 +84,7 @@ end end @testset "Regression" begin - @testset "for issue #$i" for i in [21, 26, 57, 109, 152, 163, 314] + @testset "for issue #$i" for i in [21, 26, 57, 109, 152, 163] include("regression/issue$(lpad(string(i), 3, "0")).jl") end end