From 939ae7ef60ff9c1498b5c99e2d6e4e15b5e637c3 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Mon, 30 Sep 2019 16:59:13 +0200 Subject: [PATCH] Remove `readline`, `eachline`, and `readuntil` from #477, #541, and #575 --- README.md | 6 ------ src/Compat.jl | 20 -------------------- test/old.jl | 41 +++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 41 ----------------------------------------- 4 files changed, 41 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index fdc967d0d..fad54de45 100644 --- a/README.md +++ b/README.md @@ -120,12 +120,6 @@ Currently, the `@compat` macro supports the following syntaxes: * `isnothing` for testing if a variable is equal to `nothing` ([#29674]). -* `Compat.readline` with `keep` keyword argument ([#25646]) - -* `Compat.eachline` with `keep` keyword argument ([#25646]) - -* `Compat.readuntil` with `keep` keyword argument ([#25646]) - * `Compat.invokelatest` supports keywords ([#22646]). * `Cmd` elements can be accessed as if the `Cmd` were an array of strings for 0.6 and below ([#21197]). diff --git a/src/Compat.jl b/src/Compat.jl index b3937c240..4afd0cbc1 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -13,26 +13,6 @@ end # module TypeUtils include("compatmacro.jl") -# https://github.com/JuliaLang/julia/pull/25646 -@static if VERSION < v"0.7.0-DEV.3510" - # 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; keep::Bool=false) = Base.eachline(s; chomp=!keep) - - stripdelim(s, d::Union{Char,UInt8}) = s[end] == Char(d) ? s[1:prevind(s,lastindex(s))] : s - stripdelim(s, d::AbstractString) = endswith(s, d) ? s[1:prevind(s,lastindex(s),length(d))] : s - function readuntil(f, d; keep::Bool = false) - s = Base.readuntil(f, d) - if keep || isempty(s) - return s - else - return stripdelim(s, d) - end - end - readuntil(f, d::Vector{T}; keep::Bool = false) where {T<:Union{UInt8,Char}} = convert(Vector{T}, readuntil(f, String(d), keep=keep)) -end - # https://github.com/JuliaLang/julia/pull/22646 if VERSION < v"0.7.0-DEV.1139" function invokelatest(f, args...; kwargs...) diff --git a/test/old.jl b/test/old.jl index 09d8e60aa..f5ae0ca77 100644 --- a/test/old.jl +++ b/test/old.jl @@ -68,3 +68,44 @@ end @test !isabstracttype(StridedArray) # 0.7 @test isconcretetype(Int) + +# PR 20203 +@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 25646 +for (t, s, m, kept) in [ + ("a", "ab", "a", "a"), + ("b", "ab", "b", "b"), + ("α", "αγ", "α", "α"), + ("ab", "abc", "ab", "ab"), + ("bc", "abc", "bc", "bc"), + ("αβ", "αβγ", "αβ", "αβ"), + ("aaabc", "ab", "aa", "aaab"), + ("aaabc", "ac", "aaabc", "aaabc"), + ("aaabc", "aab", "a", "aaab"), + ("aaabc", "aac", "aaabc", "aaabc"), + ("αααβγ", "αβ", "αα", "αααβ"), + ("αααβγ", "ααβ", "α", "αααβ"), + ("αααβγ", "αγ", "αααβγ", "αααβγ"), + ("barbarbarians", "barbarian", "bar", "barbarbarian"), + ("abcaabcaabcxl", "abcaabcx", "abca", "abcaabcaabcx"), + ("abbaabbaabbabbaax", "abbaabbabbaax", "abba", "abbaabbaabbabbaax"), + ("abbaabbabbaabbaabbabbaax", "abbaabbabbaax", "abbaabbabba", "abbaabbabbaabbaabbabbaax"), + ] + local t, s, m, kept + @test Compat.readuntil(IOBuffer(t), s) == m + @test Compat.readuntil(IOBuffer(t), s, keep=true) == kept + @test Compat.readuntil(IOBuffer(t), SubString(s, firstindex(s))) == m + @test Compat.readuntil(IOBuffer(t), SubString(s, firstindex(s)), keep=true) == kept + @test Compat.readuntil(IOBuffer(t), GenericString(s)) == m + @test Compat.readuntil(IOBuffer(t), GenericString(s), keep=true) == kept + @test Compat.readuntil(IOBuffer(t), Vector{UInt8}(codeunits(s))) == Vector{UInt8}(codeunits(m)) + @test Compat.readuntil(IOBuffer(t), Vector{UInt8}(codeunits(s)), keep=true) == Vector{UInt8}(codeunits(kept)) + @test Compat.readuntil(IOBuffer(t), collect(s)::Vector{Char}) == Vector{Char}(m) + @test Compat.readuntil(IOBuffer(t), collect(s)::Vector{Char}, keep=true) == Vector{Char}(kept) +end diff --git a/test/runtests.jl b/test/runtests.jl index e8842d220..289587ea8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -67,47 +67,6 @@ for x in (3.1, -17, 3//4, big(111.1), Inf) @test minmax(x) == (x, x) end -# PR 20203 -@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 25646 -for (t, s, m, kept) in [ - ("a", "ab", "a", "a"), - ("b", "ab", "b", "b"), - ("α", "αγ", "α", "α"), - ("ab", "abc", "ab", "ab"), - ("bc", "abc", "bc", "bc"), - ("αβ", "αβγ", "αβ", "αβ"), - ("aaabc", "ab", "aa", "aaab"), - ("aaabc", "ac", "aaabc", "aaabc"), - ("aaabc", "aab", "a", "aaab"), - ("aaabc", "aac", "aaabc", "aaabc"), - ("αααβγ", "αβ", "αα", "αααβ"), - ("αααβγ", "ααβ", "α", "αααβ"), - ("αααβγ", "αγ", "αααβγ", "αααβγ"), - ("barbarbarians", "barbarian", "bar", "barbarbarian"), - ("abcaabcaabcxl", "abcaabcx", "abca", "abcaabcaabcx"), - ("abbaabbaabbabbaax", "abbaabbabbaax", "abba", "abbaabbaabbabbaax"), - ("abbaabbabbaabbaabbabbaax", "abbaabbabbaax", "abbaabbabba", "abbaabbabbaabbaabbabbaax"), - ] - local t, s, m, kept - @test Compat.readuntil(IOBuffer(t), s) == m - @test Compat.readuntil(IOBuffer(t), s, keep=true) == kept - @test Compat.readuntil(IOBuffer(t), SubString(s, firstindex(s))) == m - @test Compat.readuntil(IOBuffer(t), SubString(s, firstindex(s)), keep=true) == kept - @test Compat.readuntil(IOBuffer(t), GenericString(s)) == m - @test Compat.readuntil(IOBuffer(t), GenericString(s), keep=true) == kept - @test Compat.readuntil(IOBuffer(t), Vector{UInt8}(codeunits(s))) == Vector{UInt8}(codeunits(m)) - @test Compat.readuntil(IOBuffer(t), Vector{UInt8}(codeunits(s)), keep=true) == Vector{UInt8}(codeunits(kept)) - @test Compat.readuntil(IOBuffer(t), collect(s)::Vector{Char}) == Vector{Char}(m) - @test Compat.readuntil(IOBuffer(t), collect(s)::Vector{Char}, keep=true) == Vector{Char}(kept) -end - # invokelatest with keywords pr22646(x; y=0) = 1 let foo() = begin