diff --git a/README.md b/README.md index 6987f2e1b..e9da4bf69 100644 --- a/README.md +++ b/README.md @@ -124,10 +124,6 @@ Currently, the `@compat` macro supports the following syntaxes: * `search` is now `findfirst`/`findnext` and `rsearch` is now `findlast`/`findprev`, sometimes combined with `isequal` or `in` ([#24673], [#26436]). -* `Compat.findfirst`, `Compat.findnext`, `Compat.findlast` and `Compat.findprev`, - return `nothing` when no match is found (rather than `0` or `0:-1`) - as on Julia 0.7 ([#24673], [#26149]). - * `findin(a, b)` is now `findall(in(b), a)` ([#24673]). * `Compat.indexin` accepts any iterable as first argument, returns `nothing` (rather than `0`) diff --git a/src/Compat.jl b/src/Compat.jl index bb7ff2a15..d6afd7610 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -75,55 +75,6 @@ end end end -@static if VERSION < v"0.7.0-DEV.3272" - zero2nothing(x::Integer) = x == 0 ? nothing : x - zero2nothing(x::AbstractUnitRange{<:Integer}) = x == 0:-1 ? nothing : x - zero2nothing(x) = x - - findnext(xs...) = zero2nothing(Base.findnext(xs...)) - findfirst(xs...) = zero2nothing(Base.findfirst(xs...)) - findprev(xs...) = zero2nothing(Base.findprev(xs...)) - findlast(xs...) = zero2nothing(Base.findlast(xs...)) - - Base.findnext(r::Regex, s::AbstractString, idx::Integer) = search(s, r, idx) - Base.findfirst(r::Regex, s::AbstractString) = search(s, r) - Base.findnext(c::Fix2{typeof(isequal),Char}, s::AbstractString, i::Integer) = search(s, c.x, i) - Base.findfirst(c::Fix2{typeof(isequal),Char}, s::AbstractString) = search(s, c.x) - Base.findnext(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}, i::Integer) = - search(a, b.x, i) - Base.findfirst(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}) = - search(a, b.x) - - Base.findnext(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString, i::Integer) = - search(s, c.x, i) - Base.findfirst(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString) = - search(s, c.x) - Base.findnext(t::AbstractString, s::AbstractString, i::Integer) = search(s, t, i) - Base.findfirst(t::AbstractString, s::AbstractString) = search(s, t) - - Base.findfirst(delim::Fix2{typeof(isequal),UInt8}, buf::Base.IOBuffer) = search(buf, delim.x) - - Base.findprev(c::Fix2{typeof(isequal),Char}, s::AbstractString, i::Integer) = rsearch(s, c.x, i) - Base.findlast(c::Fix2{typeof(isequal),Char}, s::AbstractString) = rsearch(s, c.x) - Base.findprev(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}, i::Integer) = - rsearch(a, b.x, i) - Base.findlast(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}) = - rsearch(a, b.x) - - Base.findprev(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString, i::Integer) = rsearch(s, c.x, i) - Base.findlast(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}}, - s::AbstractString) = rsearch(s, c.x) - Base.findprev(t::AbstractString, s::AbstractString, i::Integer) = rsearch(s, t, i) - Base.findlast(t::AbstractString, s::AbstractString) = rsearch(s, t) - - findall(b::Fix2{typeof(in)}, a) = findin(a, b.x) - # To fix ambiguity - findall(b::Fix2{typeof(in)}, a::Number) = a in b.x ? [1] : Vector{Int}() -end - @static if VERSION < v"0.7.0-DEV.4047" #26089 showable(mime, x) = mimewritable(mime, x) export showable diff --git a/test/old.jl b/test/old.jl index dfc6e48ae..453b27147 100644 --- a/test/old.jl +++ b/test/old.jl @@ -728,3 +728,40 @@ end let x = y = 1 @test objectid(x) == objectid(y) end + +# 0.7.0-DEV.3415 +for (f1, f2, i) in ((Compat.findfirst, Compat.findnext, 1), + (Compat.findlast, Compat.findprev, 2)) + # Generic methods + @test f1(isequal(0), [1, 0]) == f2(isequal(0), [1, 0], i) == 2 + @test f1(isequal(9), [1, 0]) == f2(isequal(9), [1, 0], i) == nothing + @test f1(in([0, 2]), [1, 0]) == f2(in([0, 2]), [1, 0], i) == 2 + @test f1(in([0, 2]), [1, 9]) == f2(in([0, 2]), [1, 9], i) == nothing + @test f1([true, false]) == f2([true, false], i) == 1 + @test f1([false, false]) == f2([false, false], i) == nothing + + # Specific methods + @test f2(isequal('a'), "ba", i) == f1(isequal('a'), "ba") == 2 + for S in (Int8, UInt8), T in (Int8, UInt8) + # Bug in Julia 0.6 + @test f2(isequal(S(1)), T[0, 1], i) == f1(isequal(S(1)), T[0, 1]) == 2 + @test f2(isequal(S(9)), T[0, 1], i) == f1(isequal(S(9)), T[0, 1]) == nothing + end + for chars in (['a', 'z'], Set(['a', 'z']), ('a', 'z')) + @test f2(in(chars), "ba", i) == f1(in(chars), "ba") == 2 + @test f2(in(chars), "bx", i) == f1(in(chars), "bx") == nothing + end +end +@test findnext("a", "ba", 1) == findfirst("a", "ba") == 2:2 +@test findnext("z", "ba", 1) == findfirst("z", "ba") == nothing +@test findprev("a", "ba", 2) == findlast("a", "ba") == 2:2 +@test findprev("z", "ba", 2) == findlast("z", "ba") == nothing +@test Compat.findnext("a", "ba", 1) == Compat.findfirst("a", "ba") == 2:2 +@test Compat.findnext("z", "ba", 1) == Compat.findfirst("z", "ba") == nothing +@test Compat.findprev("a", "ba", 2) == Compat.findlast("a", "ba") == 2:2 +@test Compat.findprev("z", "ba", 2) == Compat.findlast("z", "ba") == nothing + +@test findnext(r"a", "ba", 1) == findfirst(r"a", "ba") == 2:2 +@test findnext(r"z", "ba", 1) == findfirst(r"z", "ba") == nothing +@test Compat.findnext(r"a", "ba", 1) == Compat.findfirst(r"a", "ba") == 2:2 +@test Compat.findnext(r"z", "ba", 1) == Compat.findfirst(r"z", "ba") == nothing diff --git a/test/runtests.jl b/test/runtests.jl index 34aafb485..0262cd924 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,54 +82,6 @@ end @test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8 -# 0.7.0-DEV.3415 -for (f1, f2, i) in ((Compat.findfirst, Compat.findnext, 1), - (Compat.findlast, Compat.findprev, 2)) - # Generic methods - @test f1(isequal(0), [1, 0]) == f2(isequal(0), [1, 0], i) == 2 - @test f1(isequal(9), [1, 0]) == f2(isequal(9), [1, 0], i) == nothing - @test f1(in([0, 2]), [1, 0]) == f2(in([0, 2]), [1, 0], i) == 2 - @test f1(in([0, 2]), [1, 9]) == f2(in([0, 2]), [1, 9], i) == nothing - if VERSION < v"0.7.0-DEV.4592" - # test that occursin work on 0.6 - @test f1(occursin([0, 2]), [1, 0]) == f2(occursin([0, 2]), [1, 0], i) == 2 - @test f1(occursin([0, 2]), [1, 9]) == f2(occursin([0, 2]), [1, 9], i) == nothing - end - @test f1([true, false]) == f2([true, false], i) == 1 - @test f1([false, false]) == f2([false, false], i) == nothing - - # Specific methods - @test f2(isequal('a'), "ba", i) == f1(isequal('a'), "ba") == 2 - for S in (Int8, UInt8), T in (Int8, UInt8) - # Bug in Julia 0.6 - f1 === Compat.findlast && VERSION < v"0.7.0-DEV.3272" && continue - @test f2(isequal(S(1)), T[0, 1], i) == f1(isequal(S(1)), T[0, 1]) == 2 - @test f2(isequal(S(9)), T[0, 1], i) == f1(isequal(S(9)), T[0, 1]) == nothing - end - for chars in (['a', 'z'], Set(['a', 'z']), ('a', 'z')) - @test f2(in(chars), "ba", i) == f1(in(chars), "ba") == 2 - @test f2(in(chars), "bx", i) == f1(in(chars), "bx") == nothing - if VERSION < v"0.7.0-DEV.4592" - # test that occursin work on 0.6 - @test f2(occursin(chars), "ba", i) == f1(occursin(chars), "ba") == 2 - @test f2(occursin(chars), "bx", i) == f1(occursin(chars), "bx") == nothing - end - end -end -@test findnext("a", "ba", 1) == findfirst("a", "ba") == 2:2 -@test findnext("z", "ba", 1) == findfirst("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) -@test findprev("a", "ba", 2) == findlast("a", "ba") == 2:2 -@test findprev("z", "ba", 2) == findlast("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) -@test Compat.findnext("a", "ba", 1) == Compat.findfirst("a", "ba") == 2:2 -@test Compat.findnext("z", "ba", 1) == Compat.findfirst("z", "ba") == nothing -@test Compat.findprev("a", "ba", 2) == Compat.findlast("a", "ba") == 2:2 -@test Compat.findprev("z", "ba", 2) == Compat.findlast("z", "ba") == nothing - -@test findnext(r"a", "ba", 1) == findfirst(r"a", "ba") == 2:2 -@test findnext(r"z", "ba", 1) == findfirst(r"z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) -@test Compat.findnext(r"a", "ba", 1) == Compat.findfirst(r"a", "ba") == 2:2 -@test Compat.findnext(r"z", "ba", 1) == Compat.findfirst(r"z", "ba") == nothing - @test findall([true, false, true]) == [1, 3] @test findall(in([1, 2]), [1]) == [1] if VERSION < v"0.7.0-DEV.4592"