diff --git a/README.md b/README.md index fdd7604fd..cce5f5e4d 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `Compat.readline` with `keep` keyword argument ([#25646]) +* `Compat.eachline` with `keep` keyword argument ([#25646]) + * `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s ([#19841]) * The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation. diff --git a/src/Compat.jl b/src/Compat.jl index a36734429..53bfd3bd2 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -348,6 +348,7 @@ end # not exported # chomp parameter preserved for compatibility with earliear Compat versions readline(s::IO=STDIN; chomp::Bool=true, keep::Bool=!chomp) = Base.readline(s; chomp=!keep) + eachline(s; chomp::Bool=true, keep::Bool=!chomp) = Base.eachline(s; chomp=!keep) end # https://github.com/JuliaLang/julia/pull/18727 diff --git a/test/runtests.jl b/test/runtests.jl index 4201f5feb..59f2e4fdb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -597,6 +597,9 @@ end @test Compat.readline(IOBuffer("Hello, World!\n")) == "Hello, World!" @test Compat.readline(IOBuffer("x\n"), keep=false) == "x" @test Compat.readline(IOBuffer("x\n"), keep=true) == "x\n" +@test collect(Compat.eachline(IOBuffer("x\ny"))) == ["x", "y"] +@test collect(Compat.eachline(IOBuffer("x\ny"), keep=false)) == ["x", "y"] +@test collect(Compat.eachline(IOBuffer("x\ny"), keep=true)) == ["x\n", "y"] # PR 18727 let