Skip to content

Commit

Permalink
Remove readline, eachline, and readuntil from #477, #541, and #575
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Oct 8, 2019
1 parent 896856e commit 939ae7e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 67 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down
20 changes: 0 additions & 20 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
41 changes: 41 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 0 additions & 41 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 939ae7e

Please sign in to comment.