Skip to content

Commit 379a23f

Browse files
committed
Drop compat code for Compat.find* returning nothing from #484 and #513
1 parent ebba212 commit 379a23f

File tree

4 files changed

+37
-101
lines changed

4 files changed

+37
-101
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ Currently, the `@compat` macro supports the following syntaxes:
124124
* `search` is now `findfirst`/`findnext` and `rsearch` is now `findlast`/`findprev`,
125125
sometimes combined with `isequal` or `in` ([#24673], [#26436]).
126126

127-
* `Compat.findfirst`, `Compat.findnext`, `Compat.findlast` and `Compat.findprev`,
128-
return `nothing` when no match is found (rather than `0` or `0:-1`)
129-
as on Julia 0.7 ([#24673], [#26149]).
130-
131127
* `findin(a, b)` is now `findall(in(b), a)` ([#24673]).
132128

133129
* `Compat.indexin` accepts any iterable as first argument, returns `nothing` (rather than `0`)

src/Compat.jl

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -75,55 +75,6 @@ end
7575
end
7676
end
7777

78-
@static if VERSION < v"0.7.0-DEV.3272"
79-
zero2nothing(x::Integer) = x == 0 ? nothing : x
80-
zero2nothing(x::AbstractUnitRange{<:Integer}) = x == 0:-1 ? nothing : x
81-
zero2nothing(x) = x
82-
83-
findnext(xs...) = zero2nothing(Base.findnext(xs...))
84-
findfirst(xs...) = zero2nothing(Base.findfirst(xs...))
85-
findprev(xs...) = zero2nothing(Base.findprev(xs...))
86-
findlast(xs...) = zero2nothing(Base.findlast(xs...))
87-
88-
Base.findnext(r::Regex, s::AbstractString, idx::Integer) = search(s, r, idx)
89-
Base.findfirst(r::Regex, s::AbstractString) = search(s, r)
90-
Base.findnext(c::Fix2{typeof(isequal),Char}, s::AbstractString, i::Integer) = search(s, c.x, i)
91-
Base.findfirst(c::Fix2{typeof(isequal),Char}, s::AbstractString) = search(s, c.x)
92-
Base.findnext(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}, i::Integer) =
93-
search(a, b.x, i)
94-
Base.findfirst(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}) =
95-
search(a, b.x)
96-
97-
Base.findnext(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}},
98-
s::AbstractString, i::Integer) =
99-
search(s, c.x, i)
100-
Base.findfirst(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}},
101-
s::AbstractString) =
102-
search(s, c.x)
103-
Base.findnext(t::AbstractString, s::AbstractString, i::Integer) = search(s, t, i)
104-
Base.findfirst(t::AbstractString, s::AbstractString) = search(s, t)
105-
106-
Base.findfirst(delim::Fix2{typeof(isequal),UInt8}, buf::Base.IOBuffer) = search(buf, delim.x)
107-
108-
Base.findprev(c::Fix2{typeof(isequal),Char}, s::AbstractString, i::Integer) = rsearch(s, c.x, i)
109-
Base.findlast(c::Fix2{typeof(isequal),Char}, s::AbstractString) = rsearch(s, c.x)
110-
Base.findprev(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}, i::Integer) =
111-
rsearch(a, b.x, i)
112-
Base.findlast(b::Fix2{typeof(isequal),<:Union{Int8,UInt8}}, a::Vector{<:Union{Int8,UInt8}}) =
113-
rsearch(a, b.x)
114-
115-
Base.findprev(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}},
116-
s::AbstractString, i::Integer) = rsearch(s, c.x, i)
117-
Base.findlast(c::Fix2{typeof(in),<:Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}},
118-
s::AbstractString) = rsearch(s, c.x)
119-
Base.findprev(t::AbstractString, s::AbstractString, i::Integer) = rsearch(s, t, i)
120-
Base.findlast(t::AbstractString, s::AbstractString) = rsearch(s, t)
121-
122-
findall(b::Fix2{typeof(in)}, a) = findin(a, b.x)
123-
# To fix ambiguity
124-
findall(b::Fix2{typeof(in)}, a::Number) = a in b.x ? [1] : Vector{Int}()
125-
end
126-
12778
@static if VERSION < v"0.7.0-DEV.4047" #26089
12879
showable(mime, x) = mimewritable(mime, x)
12980
export showable

test/old.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,40 @@ end
728728
let x = y = 1
729729
@test objectid(x) == objectid(y)
730730
end
731+
732+
# 0.7.0-DEV.3415
733+
for (f1, f2, i) in ((Compat.findfirst, Compat.findnext, 1),
734+
(Compat.findlast, Compat.findprev, 2))
735+
# Generic methods
736+
@test f1(isequal(0), [1, 0]) == f2(isequal(0), [1, 0], i) == 2
737+
@test f1(isequal(9), [1, 0]) == f2(isequal(9), [1, 0], i) == nothing
738+
@test f1(in([0, 2]), [1, 0]) == f2(in([0, 2]), [1, 0], i) == 2
739+
@test f1(in([0, 2]), [1, 9]) == f2(in([0, 2]), [1, 9], i) == nothing
740+
@test f1([true, false]) == f2([true, false], i) == 1
741+
@test f1([false, false]) == f2([false, false], i) == nothing
742+
743+
# Specific methods
744+
@test f2(isequal('a'), "ba", i) == f1(isequal('a'), "ba") == 2
745+
for S in (Int8, UInt8), T in (Int8, UInt8)
746+
# Bug in Julia 0.6
747+
@test f2(isequal(S(1)), T[0, 1], i) == f1(isequal(S(1)), T[0, 1]) == 2
748+
@test f2(isequal(S(9)), T[0, 1], i) == f1(isequal(S(9)), T[0, 1]) == nothing
749+
end
750+
for chars in (['a', 'z'], Set(['a', 'z']), ('a', 'z'))
751+
@test f2(in(chars), "ba", i) == f1(in(chars), "ba") == 2
752+
@test f2(in(chars), "bx", i) == f1(in(chars), "bx") == nothing
753+
end
754+
end
755+
@test findnext("a", "ba", 1) == findfirst("a", "ba") == 2:2
756+
@test findnext("z", "ba", 1) == findfirst("z", "ba") == nothing
757+
@test findprev("a", "ba", 2) == findlast("a", "ba") == 2:2
758+
@test findprev("z", "ba", 2) == findlast("z", "ba") == nothing
759+
@test Compat.findnext("a", "ba", 1) == Compat.findfirst("a", "ba") == 2:2
760+
@test Compat.findnext("z", "ba", 1) == Compat.findfirst("z", "ba") == nothing
761+
@test Compat.findprev("a", "ba", 2) == Compat.findlast("a", "ba") == 2:2
762+
@test Compat.findprev("z", "ba", 2) == Compat.findlast("z", "ba") == nothing
763+
764+
@test findnext(r"a", "ba", 1) == findfirst(r"a", "ba") == 2:2
765+
@test findnext(r"z", "ba", 1) == findfirst(r"z", "ba") == nothing
766+
@test Compat.findnext(r"a", "ba", 1) == Compat.findfirst(r"a", "ba") == 2:2
767+
@test Compat.findnext(r"z", "ba", 1) == Compat.findfirst(r"z", "ba") == nothing

test/runtests.jl

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -82,54 +82,6 @@ end
8282

8383
@test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8
8484

85-
# 0.7.0-DEV.3415
86-
for (f1, f2, i) in ((Compat.findfirst, Compat.findnext, 1),
87-
(Compat.findlast, Compat.findprev, 2))
88-
# Generic methods
89-
@test f1(isequal(0), [1, 0]) == f2(isequal(0), [1, 0], i) == 2
90-
@test f1(isequal(9), [1, 0]) == f2(isequal(9), [1, 0], i) == nothing
91-
@test f1(in([0, 2]), [1, 0]) == f2(in([0, 2]), [1, 0], i) == 2
92-
@test f1(in([0, 2]), [1, 9]) == f2(in([0, 2]), [1, 9], i) == nothing
93-
if VERSION < v"0.7.0-DEV.4592"
94-
# test that occursin work on 0.6
95-
@test f1(occursin([0, 2]), [1, 0]) == f2(occursin([0, 2]), [1, 0], i) == 2
96-
@test f1(occursin([0, 2]), [1, 9]) == f2(occursin([0, 2]), [1, 9], i) == nothing
97-
end
98-
@test f1([true, false]) == f2([true, false], i) == 1
99-
@test f1([false, false]) == f2([false, false], i) == nothing
100-
101-
# Specific methods
102-
@test f2(isequal('a'), "ba", i) == f1(isequal('a'), "ba") == 2
103-
for S in (Int8, UInt8), T in (Int8, UInt8)
104-
# Bug in Julia 0.6
105-
f1 === Compat.findlast && VERSION < v"0.7.0-DEV.3272" && continue
106-
@test f2(isequal(S(1)), T[0, 1], i) == f1(isequal(S(1)), T[0, 1]) == 2
107-
@test f2(isequal(S(9)), T[0, 1], i) == f1(isequal(S(9)), T[0, 1]) == nothing
108-
end
109-
for chars in (['a', 'z'], Set(['a', 'z']), ('a', 'z'))
110-
@test f2(in(chars), "ba", i) == f1(in(chars), "ba") == 2
111-
@test f2(in(chars), "bx", i) == f1(in(chars), "bx") == nothing
112-
if VERSION < v"0.7.0-DEV.4592"
113-
# test that occursin work on 0.6
114-
@test f2(occursin(chars), "ba", i) == f1(occursin(chars), "ba") == 2
115-
@test f2(occursin(chars), "bx", i) == f1(occursin(chars), "bx") == nothing
116-
end
117-
end
118-
end
119-
@test findnext("a", "ba", 1) == findfirst("a", "ba") == 2:2
120-
@test findnext("z", "ba", 1) == findfirst("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing)
121-
@test findprev("a", "ba", 2) == findlast("a", "ba") == 2:2
122-
@test findprev("z", "ba", 2) == findlast("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing)
123-
@test Compat.findnext("a", "ba", 1) == Compat.findfirst("a", "ba") == 2:2
124-
@test Compat.findnext("z", "ba", 1) == Compat.findfirst("z", "ba") == nothing
125-
@test Compat.findprev("a", "ba", 2) == Compat.findlast("a", "ba") == 2:2
126-
@test Compat.findprev("z", "ba", 2) == Compat.findlast("z", "ba") == nothing
127-
128-
@test findnext(r"a", "ba", 1) == findfirst(r"a", "ba") == 2:2
129-
@test findnext(r"z", "ba", 1) == findfirst(r"z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing)
130-
@test Compat.findnext(r"a", "ba", 1) == Compat.findfirst(r"a", "ba") == 2:2
131-
@test Compat.findnext(r"z", "ba", 1) == Compat.findfirst(r"z", "ba") == nothing
132-
13385
@test findall([true, false, true]) == [1, 3]
13486
@test findall(in([1, 2]), [1]) == [1]
13587
if VERSION < v"0.7.0-DEV.4592"

0 commit comments

Comments
 (0)