Skip to content

Commit

Permalink
test fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jul 9, 2023
1 parent 5038900 commit aa87b29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ julia> rm("my_file.txt")
readuntil(filename::AbstractString, delim; kw...) = open(io->readuntil(io, delim; kw...), convert(String, filename)::String)
readuntil(stream::IO, delim::UInt8; kw...) = _unsafe_take!(copyuntil(IOBuffer(sizehint=70), stream, delim; kw...))
readuntil(stream::IO, delim::Union{AbstractChar, AbstractString}; kw...) = String(_unsafe_take!(copyuntil(IOBuffer(sizehint=70), stream, delim; kw...)))
readuntil(stream::IO, delim::T; keep::Bool=false) where T = _copyuntil(Vector{T}(), s, delim, keep)
readuntil(stream::IO, delim::T; keep::Bool=false) where T = _copyuntil(Vector{T}(), stream, delim, keep)


"""
Expand Down
15 changes: 15 additions & 0 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,21 @@ end
@test isempty(itr) # now it is empty
end

@testset "readuntil/copyuntil fallbacks" begin
# test fallback for generic delim::T
buf = IOBuffer()
fib = [1,1,2,3,5,8,13,21]
write(buf, fib)
@test readuntil(seekstart(buf), 21) == fib[1:end-1]
@test readuntil(buf, 21) == Int[]
@test readuntil(seekstart(buf), 21; keep=true) == fib
out = IOBuffer()
@test copyuntil(out, seekstart(buf), 21) === out
@test reinterpret(Int, take!(out)) == fib[1:end-1]
@test copyuntil(out, seekstart(buf), 21; keep=true) === out
@test reinterpret(Int, take!(out)) == fib
end

# more tests for reverse(eachline)
@testset "reverse(eachline)" begin
lines = vcat(repr.(1:4), ' '^50000 .* repr.(5:10), repr.(11:10^5))
Expand Down

0 comments on commit aa87b29

Please sign in to comment.