diff --git a/NEWS.md b/NEWS.md index 091ab7e77763e..684a5b28cef24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -562,8 +562,8 @@ Library improvements * `diagm` now accepts several diagonal index/vector `Pair`s ([#24047]). - * New function `equalto(x)`, which returns a function that compares its argument to `x` - using `isequal` ([#23812]). + * `isequal`, `==`, and `in` have one argument "curried" forms. For example `isequal(x)` + returns a function that compares its argument to `x` using `isequal` ([#23812]). * `reinterpret` now works on any AbstractArray using the new `ReinterpretArray` type. This supersedes the old behavior of reinterpret on Arrays. As a result, reinterpreting @@ -1027,7 +1027,7 @@ Deprecated or removed `F.Q` instead of `F[:Q]` ([#25184]). * `search` and `rsearch` have been deprecated in favor of `findfirst`/`findnext` and - `findlast`/`findprev` respectively, in combination with the new `equalto` and `occursin` + `findlast`/`findprev` respectively, in combination with curried `isequal` and `in` predicates for some methods ([#24673] * `ismatch(regex, str)` has been deprecated in favor of `contains(str, regex)` ([#24673]). @@ -1038,7 +1038,7 @@ Deprecated or removed `similar(::Associative, ::Pair{K, V})` has been deprecated in favour of `empty(::Associative, K, V)` ([#24390]). - * `findin(a, b)` has been deprecated in favor of `findall(occursin(b), a)` ([#24673]). + * `findin(a, b)` has been deprecated in favor of `findall(in(b), a)` ([#24673]). * `module_name` has been deprecated in favor of a new, general `nameof` function. Similarly, the unexported `Base.function_name` and `Base.datatype_name` have been deprecated in favor diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 80c1a2d285273..16c09b3ba9621 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1179,7 +1179,7 @@ get(A::AbstractArray, I::Dims, default) = checkbounds(Bool, A, I...) ? A[I...] : function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T # 1d is not linear indexing - ind = findall(occursin(indices1(A)), I) + ind = findall(in(indices1(A)), I) X[ind] = A[I[ind]] Xind = indices1(X) X[first(Xind):first(ind)-1] = default @@ -1188,7 +1188,7 @@ function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{AbstractRange,Ab end function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T # Linear indexing - ind = findall(occursin(1:length(A)), I) + ind = findall(in(1:length(A)), I) X[ind] = A[I[ind]] X[1:first(ind)-1] = default X[last(ind)+1:length(X)] = default @@ -1361,7 +1361,7 @@ _cs(d, a, b) = (a == b ? a : throw(DimensionMismatch( "mismatch in dimension $d (expected $a got $b)"))) dims2cat(::Val{n}) where {n} = ntuple(i -> (i == n), Val(n)) -dims2cat(dims) = ntuple(occursin(dims), maximum(dims)) +dims2cat(dims) = ntuple(in(dims), maximum(dims)) cat(dims, X...) = cat_t(dims, promote_eltypeof(X...), X...) diff --git a/base/array.jl b/base/array.jl index 3bb6c89d00e7a..b48cb9cc649eb 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1666,7 +1666,7 @@ julia> findfirst(iseven, A) julia> findfirst(x -> x>10, A) # returns nothing, but not printed in the REPL -julia> findfirst(equalto(4), A) +julia> findfirst(isequal(4), A) 2 julia> A = [1 4; 2 2] diff --git a/base/client.jl b/base/client.jl index ca76fed2ed24b..5a237c00b4d14 100644 --- a/base/client.jl +++ b/base/client.jl @@ -218,7 +218,7 @@ function parse_input_line(s::String; filename::String="none", depwarn=true) ccall(:jl_parse_input_line, Any, (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t), s, sizeof(s), filename, sizeof(filename)) end - if ex isa Symbol && all(equalto('_'), string(ex)) + if ex isa Symbol && all(isequal('_'), string(ex)) # remove with 0.7 deprecation Meta.lower(Main, ex) # to get possible warning about using _ as an rvalue end diff --git a/base/deprecated.jl b/base/deprecated.jl index 5c754c65073ea..da3e9a1e23d2c 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -712,10 +712,10 @@ end @deprecate charwidth textwidth @deprecate find(x::Number) findall(!iszero, x) -@deprecate findnext(A, v, i::Integer) coalesce(findnext(equalto(v), A, i), 0) -@deprecate findfirst(A, v) coalesce(findfirst(equalto(v), A), 0) -@deprecate findprev(A, v, i::Integer) coalesce(findprev(equalto(v), A, i), 0) -@deprecate findlast(A, v) coalesce(findlast(equalto(v), A), 0) +@deprecate findnext(A, v, i::Integer) coalesce(findnext(isequal(v), A, i), 0) +@deprecate findfirst(A, v) coalesce(findfirst(isequal(v), A), 0) +@deprecate findprev(A, v, i::Integer) coalesce(findprev(isequal(v), A, i), 0) +@deprecate findlast(A, v) coalesce(findlast(isequal(v), A), 0) # to fix ambiguities introduced by deprecations findnext(pred::Function, A, i::Integer) = invoke(findnext, Tuple{Function, Any, Any}, pred, A, i) findprev(pred::Function, A, i::Integer) = invoke(findprev, Tuple{Function, Any, Any}, pred, A, i) @@ -1198,25 +1198,25 @@ end @deprecate search(str::Union{String,SubString}, re::Regex, idx::Integer) coalesce(findnext(re, str, idx), 0:-1) @deprecate search(s::AbstractString, r::Regex, idx::Integer) coalesce(findnext(r, s, idx), 0:-1) @deprecate search(s::AbstractString, r::Regex) coalesce(findfirst(r, s), 0:-1) -@deprecate search(s::AbstractString, c::Char, i::Integer) coalesce(findnext(equalto(c), s, i), 0) -@deprecate search(s::AbstractString, c::Char) coalesce(findfirst(equalto(c), s), 0) -@deprecate search(a::ByteArray, b::Union{Int8,UInt8}, i::Integer) coalesce(findnext(equalto(b), a, i), 0) -@deprecate search(a::ByteArray, b::Union{Int8,UInt8}) coalesce(findfirst(equalto(b), a), 0) -@deprecate search(a::String, b::Union{Int8,UInt8}, i::Integer) coalesce(findnext(equalto(b), unsafe_wrap(Vector{UInt8}, a), i), 0) -@deprecate search(a::String, b::Union{Int8,UInt8}) coalesce(findfirst(equalto(b), unsafe_wrap(Vector{UInt8}, a)), 0) -@deprecate search(a::ByteArray, b::Char, i::Integer) coalesce(findnext(equalto(UInt8(b)), a, i), 0) -@deprecate search(a::ByteArray, b::Char) coalesce(findfirst(equalto(UInt8(b)), a), 0) - -@deprecate search(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}, i::Integer) coalesce(findnext(occursin(c), s, i), 0) -@deprecate search(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}) coalesce(findfirst(occursin(c), s), 0) +@deprecate search(s::AbstractString, c::Char, i::Integer) coalesce(findnext(isequal(c), s, i), 0) +@deprecate search(s::AbstractString, c::Char) coalesce(findfirst(isequal(c), s), 0) +@deprecate search(a::ByteArray, b::Union{Int8,UInt8}, i::Integer) coalesce(findnext(isequal(b), a, i), 0) +@deprecate search(a::ByteArray, b::Union{Int8,UInt8}) coalesce(findfirst(isequal(b), a), 0) +@deprecate search(a::String, b::Union{Int8,UInt8}, i::Integer) coalesce(findnext(isequal(b), unsafe_wrap(Vector{UInt8}, a), i), 0) +@deprecate search(a::String, b::Union{Int8,UInt8}) coalesce(findfirst(isequal(b), unsafe_wrap(Vector{UInt8}, a)), 0) +@deprecate search(a::ByteArray, b::Char, i::Integer) coalesce(findnext(isequal(UInt8(b)), a, i), 0) +@deprecate search(a::ByteArray, b::Char) coalesce(findfirst(isequal(UInt8(b)), a), 0) + +@deprecate search(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}, i::Integer) coalesce(findnext(in(c), s, i), 0) +@deprecate search(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}) coalesce(findfirst(in(c), s), 0) @deprecate search(s::AbstractString, t::AbstractString, i::Integer) coalesce(findnext(t, s, i), 0:-1) @deprecate search(s::AbstractString, t::AbstractString) coalesce(findfirst(t, s), 0:-1) -@deprecate search(buf::IOBuffer, delim::UInt8) coalesce(findfirst(equalto(delim), buf), 0) -@deprecate search(buf::Base.GenericIOBuffer, delim::UInt8) coalesce(findfirst(equalto(delim), buf), 0) +@deprecate search(buf::IOBuffer, delim::UInt8) coalesce(findfirst(isequal(delim), buf), 0) +@deprecate search(buf::Base.GenericIOBuffer, delim::UInt8) coalesce(findfirst(isequal(delim), buf), 0) -@deprecate rsearch(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}, i::Integer) coalesce(findprev(occursin(c), s, i), 0) -@deprecate rsearch(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}) coalesce(findlast(occursin(c), s), 0) +@deprecate rsearch(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}, i::Integer) coalesce(findprev(in(c), s, i), 0) +@deprecate rsearch(s::AbstractString, c::Union{Tuple{Vararg{Char}},AbstractVector{Char},Set{Char}}) coalesce(findlast(in(c), s), 0) @deprecate rsearch(s::AbstractString, t::AbstractString, i::Integer) coalesce(findprev(t, s, i), 0:-1) @deprecate rsearch(s::AbstractString, t::AbstractString) coalesce(findlast(t, s), 0:-1) @@ -1224,25 +1224,25 @@ end @deprecate rsearch(str::Union{String,SubString}, re::Regex) coalesce(findlast(re, str), 0:-1) @deprecate rsearch(s::AbstractString, r::Regex, idx::Integer) coalesce(findprev(r, s, idx), 0:-1) @deprecate rsearch(s::AbstractString, r::Regex) coalesce(findlast(r, s), 0:-1) -@deprecate rsearch(s::AbstractString, c::Char, i::Integer) coalesce(findprev(equalto(c), s, i), 0) -@deprecate rsearch(s::AbstractString, c::Char) coalesce(findlast(equalto(c), s), 0) -@deprecate rsearch(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = lastindex(a)) coalesce(findprev(equalto(b), a, i), 0) -@deprecate rsearch(a::String, b::Union{Int8,UInt8}, i::Integer = lastindex(a)) coalesce(findprev(equalto(Char(b)), a, i), 0) -@deprecate rsearch(a::ByteArray, b::Char, i::Integer = lastindex(a)) coalesce(findprev(equalto(UInt8(b)), a, i), 0) +@deprecate rsearch(s::AbstractString, c::Char, i::Integer) coalesce(findprev(isequal(c), s, i), 0) +@deprecate rsearch(s::AbstractString, c::Char) coalesce(findlast(isequal(c), s), 0) +@deprecate rsearch(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = lastindex(a)) coalesce(findprev(isequal(b), a, i), 0) +@deprecate rsearch(a::String, b::Union{Int8,UInt8}, i::Integer = lastindex(a)) coalesce(findprev(isequal(Char(b)), a, i), 0) +@deprecate rsearch(a::ByteArray, b::Char, i::Integer = lastindex(a)) coalesce(findprev(isequal(UInt8(b)), a, i), 0) @deprecate searchindex(s::AbstractString, t::AbstractString) first(coalesce(findfirst(t, s), 0:-1)) @deprecate searchindex(s::AbstractString, t::AbstractString, i::Integer) first(coalesce(findnext(t, s, i), 0:-1)) @deprecate rsearchindex(s::AbstractString, t::AbstractString) first(coalesce(findlast(t, s), 0:-1)) @deprecate rsearchindex(s::AbstractString, t::AbstractString, i::Integer) first(coalesce(findprev(t, s, i), 0:-1)) -@deprecate searchindex(s::AbstractString, c::Char) coalesce(findfirst(equalto(c), s), 0) -@deprecate searchindex(s::AbstractString, c::Char, i::Integer) coalesce(findnext(equalto(c), s, i), 0) -@deprecate rsearchindex(s::AbstractString, c::Char) coalesce(findlast(equalto(c), s), 0) -@deprecate rsearchindex(s::AbstractString, c::Char, i::Integer) coalesce(findprev(equalto(c), s, i), 0) +@deprecate searchindex(s::AbstractString, c::Char) coalesce(findfirst(isequal(c), s), 0) +@deprecate searchindex(s::AbstractString, c::Char, i::Integer) coalesce(findnext(isequal(c), s, i), 0) +@deprecate rsearchindex(s::AbstractString, c::Char) coalesce(findlast(isequal(c), s), 0) +@deprecate rsearchindex(s::AbstractString, c::Char, i::Integer) coalesce(findprev(isequal(c), s, i), 0) @deprecate ismatch(r::Regex, s::AbstractString) contains(s, r) -@deprecate findin(a, b) findall(occursin(b), a) +@deprecate findin(a, b) findall(in(b), a) @deprecate find findall @deprecate find(A::AbstractVector) findall(A) diff --git a/base/exports.jl b/base/exports.jl index 05e1bbe302fa5..2c339598c8947 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -449,7 +449,6 @@ export contains, eachmatch, endswith, - equalto, findall, findfirst, findlast, @@ -459,7 +458,6 @@ export findmax!, findnext, findprev, - occursin, match, searchsorted, searchsortedfirst, diff --git a/base/methodshow.jl b/base/methodshow.jl index 53c5d7bd1b465..95b1104f5326c 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -11,7 +11,7 @@ function argtype_decl(env, n, sig::DataType, i::Int, nargs, isva::Bool) # -> (ar n = n.args[1] # handle n::T in arg list end s = string(n) - i = findfirst(equalto('#'), s) + i = findfirst(isequal('#'), s) if i !== nothing s = s[1:i-1] end diff --git a/base/operators.jl b/base/operators.jl index e918dcec16627..b61e265068666 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -809,43 +809,59 @@ julia> filter(!isalpha, str) """ !(f::Function) = (x...)->!f(x...) -struct EqualTo{T} <: Function +""" + Fix2(f, x) + +A type representing a partially-applied version of function `f`, with the second +argument fixed to the value "x". +In other words, `Fix2(f, x)` behaves similarly to `y->f(y, x)`. +""" +struct Fix2{F,T} <: Function + f::F x::T - EqualTo(x::T) where {T} = new{T}(x) + Fix2(f::F, x::T) where {F,T} = new{F,T}(f, x) + Fix2(f::Type{F}, x::T) where {F,T} = new{Type{F},T}(f, x) end -(f::EqualTo)(y) = isequal(f.x, y) +(f::Fix2)(y) = f.f(y, f.x) """ - equalto(x) + isequal(x) -Create a function that compares its argument to `x` using [`isequal`](@ref); i.e. returns -`y->isequal(x,y)`. +Create a function that compares its argument to `x` using [`isequal`](@ref), i.e. +a function equivalent to `y -> isequal(y, x)`. -The returned function is of type `Base.EqualTo`. This allows dispatching to -specialized methods by using e.g. `f::Base.EqualTo` in a method signature. +The returned function is of type `Base.Fix2{typeof(isequal)}`, which can be +used to implement specialized methods. """ -const equalto = EqualTo +isequal(x) = Fix2(isequal, x) -struct OccursIn{T} <: Function - x::T +const EqualTo = Fix2{typeof(isequal)} - OccursIn(x::T) where {T} = new{T}(x) -end +""" + ==(x) + +Create a function that compares its argument to `x` using [`==`](@ref), i.e. +a function equivalent to `y -> y == x`. -(f::OccursIn)(y) = y in f.x +The returned function is of type `Base.Fix2{typeof(==)}`, which can be +used to implement specialized methods. +""" +==(x) = Fix2(==, x) """ - occursin(x) + in(x) -Create a function that checks whether its argument is [`in`](@ref) `x`; i.e. returns -`y -> y in x`. +Create a function that checks whether its argument is [`in`](@ref) `x`, i.e. +a function equivalent to `y -> y in x`. -The returned function is of type `Base.OccursIn`. This allows dispatching to -specialized methods by using e.g. `f::Base.OccursIn` in a method signature. +The returned function is of type `Base.Fix2{typeof(in)}`, which can be +used to implement specialized methods. """ -const occursin = OccursIn +in(x) = Fix2(in, x) + +const OccursIn = Fix2{typeof(in)} """ splat(f) diff --git a/base/parse.jl b/base/parse.jl index 814c67c36929b..7c1f51117af5d 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -278,16 +278,16 @@ function tryparse_internal(::Type{Complex{T}}, s::Union{String,SubString{String} end # find index of ± separating real/imaginary parts (if any) - i₊ = coalesce(findnext(occursin(('+','-')), s, i), 0) + i₊ = coalesce(findnext(in(('+','-')), s, i), 0) if i₊ == i # leading ± sign - i₊ = coalesce(findnext(occursin(('+','-')), s, i₊+1), 0) + i₊ = coalesce(findnext(in(('+','-')), s, i₊+1), 0) end if i₊ != 0 && s[i₊-1] in ('e','E') # exponent sign - i₊ = coalesce(findnext(occursin(('+','-')), s, i₊+1), 0) + i₊ = coalesce(findnext(in(('+','-')), s, i₊+1), 0) end # find trailing im/i/j - iᵢ = coalesce(findprev(occursin(('m','i','j')), s, e), 0) + iᵢ = coalesce(findprev(in(('m','i','j')), s, e), 0) if iᵢ > 0 && s[iᵢ] == 'm' # im iᵢ -= 1 if s[iᵢ] != 'i' diff --git a/base/permuteddimsarray.jl b/base/permuteddimsarray.jl index de9c8c1944d7b..d50cc11678e78 100644 --- a/base/permuteddimsarray.jl +++ b/base/permuteddimsarray.jl @@ -212,7 +212,7 @@ function _copy!(P::PermutedDimsArray{T,N,perm}, src) where {T,N,perm} copyto!(parent(P), src) # it's not permuted else R1 = CartesianIndices(axes(src)[1:d]) - d1 = findfirst(equalto(d+1), perm)::Int # first permuted dim of dest + d1 = findfirst(isequal(d+1), perm)::Int # first permuted dim of dest R2 = CartesianIndices(axes(src)[d+2:d1-1]) R3 = CartesianIndices(axes(src)[d1+1:end]) _permutedims!(P, src, R1, R2, R3, d+1, d1) diff --git a/base/stream.jl b/base/stream.jl index 84d36f9606e4a..a13b8b7af3c0f 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -267,13 +267,13 @@ end function wait_readbyte(x::LibuvStream, c::UInt8) if isopen(x) # fast path - findfirst(equalto(c), x.buffer) !== nothing && return + findfirst(isequal(c), x.buffer) !== nothing && return else return end preserve_handle(x) try - while isopen(x) && coalesce(findfirst(equalto(c), x.buffer), 0) <= 0 + while isopen(x) && coalesce(findfirst(isequal(c), x.buffer), 0) <= 0 start_reading(x) # ensure we are reading wait(x.readnotify) end @@ -1074,7 +1074,7 @@ end show(io::IO, s::BufferStream) = print(io,"BufferStream() bytes waiting:",bytesavailable(s.buffer),", isopen:", s.is_open) function wait_readbyte(s::BufferStream, c::UInt8) - while isopen(s) && findfirst(equalto(c), s.buffer) === nothing + while isopen(s) && findfirst(isequal(c), s.buffer) === nothing wait(s.r_c) end end diff --git a/base/strings/search.jl b/base/strings/search.jl index ff86553c2b83f..cbe6d78e1f352 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -113,7 +113,7 @@ function findnext(testf::Function, s::AbstractString, i::Integer) return nothing end -in(c::AbstractChar, s::AbstractString) = (findfirst(equalto(c),s)!==nothing) +in(c::AbstractChar, s::AbstractString) = (findfirst(isequal(c),s)!==nothing) function _searchindex(s::Union{AbstractString,ByteArray}, t::Union{AbstractString,AbstractChar,Int8,UInt8}, @@ -124,7 +124,7 @@ function _searchindex(s::Union{AbstractString,ByteArray}, end t1, trest = Iterators.peel(t) while true - i = findnext(equalto(t1),s,i) + i = findnext(isequal(t1),s,i) if i === nothing return 0 end ii = nextind(s, i) a = Iterators.Stateful(trest) @@ -134,7 +134,7 @@ function _searchindex(s::Union{AbstractString,ByteArray}, end end -_searchindex(s::AbstractString, t::AbstractChar, i::Integer) = coalesce(findnext(equalto(t), s, i), 0) +_searchindex(s::AbstractString, t::AbstractChar, i::Integer) = coalesce(findnext(isequal(t), s, i), 0) function _search_bloom_mask(c) UInt64(1) << (c & 63) @@ -145,7 +145,7 @@ _nthbyte(a::Union{AbstractVector{UInt8},AbstractVector{Int8}}, i) = a[i] function _searchindex(s::String, t::String, i::Integer) # Check for fast case of a single byte - lastindex(t) == 1 && return coalesce(findnext(equalto(t[1]), s, i), 0) + lastindex(t) == 1 && return coalesce(findnext(isequal(t[1]), s, i), 0) _searchindex(unsafe_wrap(Vector{UInt8},s), unsafe_wrap(Vector{UInt8},t), i) end @@ -158,7 +158,7 @@ function _searchindex(s::ByteArray, t::ByteArray, i::Integer) elseif m == 0 return 0 elseif n == 1 - return coalesce(findnext(equalto(_nthbyte(t,1)), s, i), 0) + return coalesce(findnext(isequal(_nthbyte(t,1)), s, i), 0) end w = m - n @@ -295,7 +295,7 @@ function _rsearchindex(s::AbstractString, end t1, trest = Iterators.peel(Iterators.reverse(t)) while true - i = findprev(equalto(t1), s, i) + i = findprev(isequal(t1), s, i) i === nothing && return 0 ii = prevind(s, i) a = Iterators.Stateful(trest) @@ -313,7 +313,7 @@ end function _rsearchindex(s::String, t::String, i::Integer) # Check for fast case of a single byte if lastindex(t) == 1 - return coalesce(findprev(equalto(t[1]), s, i), 0) + return coalesce(findprev(isequal(t[1]), s, i), 0) elseif lastindex(t) != 0 j = i ≤ ncodeunits(s) ? nextind(s, i)-1 : i return _rsearchindex(unsafe_wrap(Vector{UInt8}, s), unsafe_wrap(Vector{UInt8}, t), j) @@ -335,7 +335,7 @@ function _rsearchindex(s::ByteArray, t::ByteArray, k::Integer) elseif m == 0 return 0 elseif n == 1 - return coalesce(findprev(equalto(_nthbyte(t,1)), s, k), 0) + return coalesce(findprev(isequal(_nthbyte(t,1)), s, k), 0) end w = m - n diff --git a/base/strings/util.jl b/base/strings/util.jl index 42a5d9efccae2..81d838b665f1c 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -269,10 +269,10 @@ split(str::T, splitter; _split(str, splitter, limit, keep, T <: SubString ? T[] : SubString{T}[]) split(str::T, splitter::Union{Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}; limit::Integer=0, keep::Bool=true) where {T<:AbstractString} = - _split(str, occursin(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) + _split(str, in(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) split(str::T, splitter::AbstractChar; limit::Integer=0, keep::Bool=true) where {T<:AbstractString} = - _split(str, equalto(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) + _split(str, isequal(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) function _split(str::AbstractString, splitter, limit::Integer, keep_empty::Bool, strs::Array) i = 1 # firstindex(str) @@ -336,10 +336,10 @@ rsplit(str::T, splitter; limit::Integer=0, keep::Bool=true) where {T<:AbstractSt _rsplit(str, splitter, limit, keep, T <: SubString ? T[] : SubString{T}[]) rsplit(str::T, splitter::Union{Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}; limit::Integer=0, keep::Bool=true) where {T<:AbstractString} = - _rsplit(str, occursin(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) + _rsplit(str, in(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) rsplit(str::T, splitter::AbstractChar; limit::Integer=0, keep::Bool=true) where {T<:AbstractString} = - _rsplit(str, equalto(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) + _rsplit(str, isequal(splitter), limit, keep, T <: SubString ? T[] : SubString{T}[]) function _rsplit(str::AbstractString, splitter, limit::Integer, keep_empty::Bool, strs::Array) n = lastindex(str) @@ -363,12 +363,12 @@ _replace(io, repl::Function, str, r, pattern::Function) = print(io, repl(str[first(r)])) replace(str::String, pat_repl::Pair{<:AbstractChar}; count::Integer=typemax(Int)) = - replace(str, equalto(first(pat_repl)) => last(pat_repl); count=count) + replace(str, isequal(first(pat_repl)) => last(pat_repl); count=count) replace(str::String, pat_repl::Pair{<:Union{Tuple{Vararg{<:AbstractChar}}, AbstractVector{<:AbstractChar},Set{<:AbstractChar}}}; count::Integer=typemax(Int)) = - replace(str, occursin(first(pat_repl)) => last(pat_repl), count=count) + replace(str, in(first(pat_repl)) => last(pat_repl), count=count) function replace(str::String, pat_repl::Pair; count::Integer=typemax(Int)) pattern, repl = pat_repl diff --git a/base/threadcall.jl b/base/threadcall.jl index 63875db389942..f6e7a2be05ddf 100644 --- a/base/threadcall.jl +++ b/base/threadcall.jl @@ -80,7 +80,7 @@ function do_threadcall(wrapper::Function, rettype::Type, argtypes::Vector, argva # wait for a worker thread to be available acquire(threadcall_restrictor) - idx = findfirst(equalto(nothing), thread_notifiers)::Int + idx = findfirst(isequal(nothing), thread_notifiers)::Int thread_notifiers[idx] = Condition() # queue up the work to be done diff --git a/doc/src/base/base.md b/doc/src/base/base.md index e62e4c0c59b33..f9a8354b90229 100644 --- a/doc/src/base/base.md +++ b/doc/src/base/base.md @@ -194,7 +194,6 @@ Base.invokelatest new Base.:(|>) Base.:(∘) -Base.equalto ``` ## Syntax diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index 68c2ccf8dff71..688791904778e 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -515,26 +515,26 @@ true You can search for the index of a particular character using the [`findfirst`](@ref) function: ```jldoctest -julia> findfirst(equalto('x'), "xylophone") +julia> findfirst(isequal('x'), "xylophone") 1 -julia> findfirst(equalto('p'), "xylophone") +julia> findfirst(isequal('p'), "xylophone") 5 -julia> findfirst(equalto('z'), "xylophone") +julia> findfirst(isequal('z'), "xylophone") ``` You can start the search for a character at a given offset by using [`findnext`](@ref) with a third argument: ```jldoctest -julia> findnext(equalto('o'), "xylophone", 1) +julia> findnext(isequal('o'), "xylophone", 1) 4 -julia> findnext(equalto('o'), "xylophone", 5) +julia> findnext(isequal('o'), "xylophone", 5) 7 -julia> findnext(equalto('o'), "xylophone", 8) +julia> findnext(isequal('o'), "xylophone", 8) ``` You can use the [`contains`](@ref) function to check if a substring is contained in a string: diff --git a/stdlib/Dates/test/ranges.jl b/stdlib/Dates/test/ranges.jl index 5daee3aded8b7..0a23921a808e0 100644 --- a/stdlib/Dates/test/ranges.jl +++ b/stdlib/Dates/test/ranges.jl @@ -28,7 +28,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test findall(occursin(dr), dr) == Int64[] + @test findall(in(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -60,7 +60,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findall(occursin(dr), dr) == [1:len;] + @test findall(in(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -86,7 +86,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test findall(occursin(dr), dr) == Int64[] + @test findall(in(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -118,7 +118,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findall(occursin(dr), dr) == [1:len;] + @test findall(in(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -146,7 +146,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test findall(occursin(dr), dr) == Int64[] + @test findall(in(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -178,7 +178,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findall(occursin(dr), dr) == [1:len;] + @test findall(in(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -204,7 +204,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test findall(occursin(dr), dr) == Int64[] + @test findall(in(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -236,7 +236,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test findall(occursin(dr), dr) == [1:len;] + @test findall(in(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -295,7 +295,7 @@ drs2 = map(x->Dates.Date(first(x)):step(x):Dates.Date(last(x)), drs) @test map(length, drs) == map(x->size(x)[1], drs) @test map(length, drs) == map(x->length(Dates.Date(first(x)):step(x):Dates.Date(last(x))), drs) @test map(length, drs) == map(x->length(reverse(x)), drs) -@test all(x->findall(occursin(x), x)==[1:length(x);], drs[1:4]) +@test all(x->findall(in(x), x)==[1:length(x);], drs[1:4]) @test isempty(dr2) @test all(x->reverse(x) == range(last(x), step=-step(x), length=length(x)), drs) @test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end]) @@ -373,7 +373,7 @@ drs = Any[dr, dr1, dr2, dr3, dr4, dr5, dr6, dr7, dr8, dr9, dr10, dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20] @test map(length, drs) == map(x->size(x)[1], drs) -@test all(x->findall(occursin(x), x) == [1:length(x);], drs[1:4]) +@test all(x->findall(in(x), x) == [1:length(x);], drs[1:4]) @test isempty(dr2) @test all(x->reverse(x) == last(x): - step(x):first(x), drs) @test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end]) @@ -559,7 +559,7 @@ drs = Any[dr, dr1, dr2, dr3, dr8, dr9, dr10, dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20] @test map(length, drs) == map(x->size(x)[1], drs) -@test all(x->findall(occursin(x), x) == [1:length(x);], drs[1:4]) +@test all(x->findall(in(x), x) == [1:length(x);], drs[1:4]) @test isempty(dr2) @test all(x->reverse(x) == last(x): - step(x):first(x), drs) @test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end]) diff --git a/stdlib/DelimitedFiles/src/DelimitedFiles.jl b/stdlib/DelimitedFiles/src/DelimitedFiles.jl index 6a2167c1ab27e..c17f22ba01604 100644 --- a/stdlib/DelimitedFiles/src/DelimitedFiles.jl +++ b/stdlib/DelimitedFiles/src/DelimitedFiles.jl @@ -487,7 +487,7 @@ function val_opts(opts) for (opt_name, opt_val) in opts in(opt_name, valid_opts) || throw(ArgumentError("unknown option $opt_name")) - opt_typ = valid_opt_types[findfirst(equalto(opt_name), valid_opts)::Int] + opt_typ = valid_opt_types[findfirst(isequal(opt_name), valid_opts)::Int] isa(opt_val, opt_typ) || throw(ArgumentError("$opt_name should be of type $opt_typ, got $(typeof(opt_val))")) d[opt_name] = opt_val diff --git a/stdlib/Distributed/test/distributed_exec.jl b/stdlib/Distributed/test/distributed_exec.jl index 9789c5af5e9b4..454548bff12cd 100644 --- a/stdlib/Distributed/test/distributed_exec.jl +++ b/stdlib/Distributed/test/distributed_exec.jl @@ -1036,7 +1036,7 @@ if DoFullTest pids=addprocs_with_testenv(4); @test_throws ErrorException rmprocs(pids; waitfor=0.001); # wait for workers to be removed - while any(occursin(procs()), pids) + while any(in(procs()), pids) sleep(0.1) end end @@ -1483,7 +1483,7 @@ function reuseport_tests() end # Ensure that the code has indeed been successfully executed everywhere - @test all(occursin(results), procs()) + @test all(in(results), procs()) end # Test that the client port is reused. SO_REUSEPORT may not be supported on diff --git a/stdlib/LibGit2/src/types.jl b/stdlib/LibGit2/src/types.jl index 46e5812da95e9..18d3b342fa6bc 100644 --- a/stdlib/LibGit2/src/types.jl +++ b/stdlib/LibGit2/src/types.jl @@ -895,8 +895,8 @@ function Base.split(ce::ConfigEntry) key = unsafe_string(ce.name) # Determine the positions of the delimiters - subsection_delim = coalesce(findfirst(equalto('.'), key), 0) - name_delim = coalesce(findlast(equalto('.'), key), 0) + subsection_delim = coalesce(findfirst(isequal('.'), key), 0) + name_delim = coalesce(findlast(isequal('.'), key), 0) section = SubString(key, 1, subsection_delim - 1) subsection = SubString(key, subsection_delim + 1, name_delim - 1) diff --git a/stdlib/LibGit2/test/libgit2.jl b/stdlib/LibGit2/test/libgit2.jl index f12cb8cc4d027..26afdabe7a18d 100644 --- a/stdlib/LibGit2/test/libgit2.jl +++ b/stdlib/LibGit2/test/libgit2.jl @@ -153,8 +153,8 @@ end @testset "Check library features" begin f = LibGit2.features() - @test findfirst(equalto(LibGit2.Consts.FEATURE_SSH), f) > 0 - @test findfirst(equalto(LibGit2.Consts.FEATURE_HTTPS), f) > 0 + @test findfirst(isequal(LibGit2.Consts.FEATURE_SSH), f) > 0 + @test findfirst(isequal(LibGit2.Consts.FEATURE_HTTPS), f) > 0 end @testset "OID" begin diff --git a/stdlib/Pkg/src/query.jl b/stdlib/Pkg/src/query.jl index 782786183929d..ce8e8b6543add 100644 --- a/stdlib/Pkg/src/query.jl +++ b/stdlib/Pkg/src/query.jl @@ -406,7 +406,7 @@ function prune_versions(reqs::Requires, deps::Dict{String,Dict{VersionNumber,Ava vmaskp[vn] = falses(luds) end for (vn,a) in fdepsp - vmind = findfirst(equalto(a.requires), uniqdepssets) + vmind = findfirst(isequal(a.requires), uniqdepssets) @assert vmind !== nothing vm = vmaskp[vn] vm[vmind] = true @@ -436,7 +436,7 @@ function prune_versions(reqs::Requires, deps::Dict{String,Dict{VersionNumber,Ava nc = length(vmask0_uniq) classes = [VersionNumber[] for c0 = 1:nc] for (vn,vm) in vmaskp - c0 = findfirst(equalto(vm), vmask0_uniq)::Int + c0 = findfirst(isequal(vm), vmask0_uniq)::Int push!(classes[c0], vn) end map(sort!, classes) diff --git a/stdlib/Pkg3/src/GraphType.jl b/stdlib/Pkg3/src/GraphType.jl index 0ddcdb96c4ed7..4d069c80d4041 100644 --- a/stdlib/Pkg3/src/GraphType.jl +++ b/stdlib/Pkg3/src/GraphType.jl @@ -1255,7 +1255,7 @@ function build_eq_classes_soft1!(graph::Graph, p0::Int) # group versions into sets that behave identically # each set is represented by its highest-valued member - repr_vers = sort!(Int[findlast(equalto(repr_vecs[w0]), cvecs) for w0 = 1:neq]) + repr_vers = sort!(Int[findlast(isequal(repr_vecs[w0]), cvecs) for w0 = 1:neq]) @assert all(repr_vers .> 0) @assert repr_vers[end] == eff_spp0 diff --git a/stdlib/Pkg3/src/Operations.jl b/stdlib/Pkg3/src/Operations.jl index c80c1498baf9a..6ee25b76ec9e7 100644 --- a/stdlib/Pkg3/src/Operations.jl +++ b/stdlib/Pkg3/src/Operations.jl @@ -239,7 +239,7 @@ function resolve_versions!(ctx::Context, pkgs::Vector{PackageSpec})::Dict{UUID,V info == nothing && continue haskey(info, "version") || continue # stdlibs might not have a version ver = VersionNumber(info["version"]) - uuid_idx = findfirst(equalto(uuid), uuids) + uuid_idx = findfirst(isequal(uuid), uuids) if uuid_idx != nothing pkg = pkgs[uuid_idx] if pkg.special_action != PKGSPEC_FREED && get(info, "pinned", false) diff --git a/stdlib/Pkg3/test/resolve.jl b/stdlib/Pkg3/test/resolve.jl index 8af36dd41ec1e..6e393c71afe96 100644 --- a/stdlib/Pkg3/test/resolve.jl +++ b/stdlib/Pkg3/test/resolve.jl @@ -66,7 +66,7 @@ function gen_versionranges(dict::Dict{K,Set{VersionNumber}}, srtvers::Vector{Ver vranges[vreq] = VersionRange[] while !isempty(vset) vn0 = minimum(vset) - i = findfirst(equalto(vn0), srtvers) + i = findfirst(isequal(vn0), srtvers) @assert i ≠ 0 pop!(vset, vn0) vn1 = vn0 diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl index 1b25f376aee70..c5f98a7095555 100644 --- a/stdlib/REPL/src/LineEdit.jl +++ b/stdlib/REPL/src/LineEdit.jl @@ -580,11 +580,11 @@ end # of the line. function edit_move_up(buf::IOBuffer) - npos = findprev(equalto(UInt8('\n')), buf.data, position(buf)) + npos = findprev(isequal(UInt8('\n')), buf.data, position(buf)) npos === nothing && return false # we're in the first line # We're interested in character count, not byte count offset = length(content(buf, npos => position(buf))) - npos2 = coalesce(findprev(equalto(UInt8('\n')), buf.data, npos-1), 0) + npos2 = coalesce(findprev(isequal(UInt8('\n')), buf.data, npos-1), 0) seek(buf, npos2) for _ = 1:offset pos = position(buf) @@ -603,10 +603,10 @@ function edit_move_up(s) end function edit_move_down(buf::IOBuffer) - npos = coalesce(findprev(equalto(UInt8('\n')), buf.data[1:buf.size], position(buf)), 0) + npos = coalesce(findprev(isequal(UInt8('\n')), buf.data[1:buf.size], position(buf)), 0) # We're interested in character count, not byte count offset = length(String(buf.data[(npos+1):(position(buf))])) - npos2 = findnext(equalto(UInt8('\n')), buf.data[1:buf.size], position(buf)+1) + npos2 = findnext(isequal(UInt8('\n')), buf.data[1:buf.size], position(buf)+1) if npos2 === nothing #we're in the last line return false end @@ -727,10 +727,10 @@ const _space = UInt8(' ') _notspace(c) = c != _space -beginofline(buf, pos=position(buf)) = coalesce(findprev(equalto(_newline), buf.data, pos), 0) +beginofline(buf, pos=position(buf)) = coalesce(findprev(isequal(_newline), buf.data, pos), 0) function lastindexline(buf, pos=position(buf)) - eol = findnext(equalto(_newline), buf.data[pos+1:buf.size], 1) + eol = findnext(isequal(_newline), buf.data[pos+1:buf.size], 1) eol === nothing ? buf.size : pos + eol - 1 end @@ -1848,7 +1848,7 @@ function move_line_start(s::MIState) if s.key_repeats > 0 move_input_start(s) else - seek(buf, coalesce(findprev(equalto(UInt8('\n')), buf.data, curpos), 0)) + seek(buf, coalesce(findprev(isequal(UInt8('\n')), buf.data, curpos), 0)) end end @@ -1861,7 +1861,7 @@ end function move_line_end(buf::IOBuffer) eof(buf) && return - pos = findnext(equalto(UInt8('\n')), buf.data, position(buf)+1) + pos = findnext(isequal(UInt8('\n')), buf.data, position(buf)+1) if pos === nothing move_input_end(buf) return diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index d1e05e66c37e3..08715103a0249 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -886,7 +886,7 @@ function setup_interface( sbuffer = LineEdit.buffer(s) curspos = position(sbuffer) seek(sbuffer, 0) - shouldeval = (bytesavailable(sbuffer) == curspos && findfirst(equalto(UInt8('\n')), sbuffer) === nothing) + shouldeval = (bytesavailable(sbuffer) == curspos && findfirst(isequal(UInt8('\n')), sbuffer) === nothing) seek(sbuffer, curspos) if curspos == 0 # if pasting at the beginning, strip leading whitespace @@ -1048,7 +1048,7 @@ input_color(r::StreamREPL) = r.input_color # heuristic function to decide if the presence of a semicolon # at the end of the expression was intended for suppressing output function ends_with_semicolon(line::AbstractString) - match = findlast(equalto(';'), line) + match = findlast(isequal(';'), line) if match !== nothing # state for comment parser, assuming that the `;` isn't in a string or comment # so input like ";#" will still thwart this to give the wrong (anti-conservative) answer diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index ec09bc8889f3f..f0bf4cbc84c52 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -42,7 +42,7 @@ function complete_symbol(sym, ffunc) lookup_module = true t = Union{} val = nothing - if coalesce(findlast(occursin(non_identifier_chars), sym), 0) < coalesce(findlast(equalto('.'), sym), 0) + if coalesce(findlast(in(non_identifier_chars), sym), 0) < coalesce(findlast(isequal('.'), sym), 0) # Find module lookup_name, name = rsplit(sym, ".", limit=2) @@ -201,7 +201,7 @@ function complete_path(path::AbstractString, pos; use_envpath=false) end matchList = String[replace(s, r"\s" => "\\ ") for s in matches] - startpos = pos - lastindex(prefix) + 1 - count(equalto(' '), prefix) + startpos = pos - lastindex(prefix) + 1 - count(isequal(' '), prefix) # The pos - lastindex(prefix) + 1 is correct due to `lastindex(prefix)-lastindex(prefix)==0`, # hence we need to add one to get the first index. This is also correct when considering # pos, because pos is the `lastindex` a larger string which `endswith(path)==true`. @@ -268,7 +268,7 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')') end braces != 1 && return 0:-1, -1 method_name_end = reverseind(s, i) - startind = nextind(s, coalesce(findprev(occursin(non_identifier_chars), s, method_name_end), 0)) + startind = nextind(s, coalesce(findprev(in(non_identifier_chars), s, method_name_end), 0)) return (startind:lastindex(s), method_name_end) end @@ -423,8 +423,8 @@ function afterusing(string::String, startpos::Int) end function bslash_completions(string, pos) - slashpos = coalesce(findprev(equalto('\\'), string, pos), 0) - if (coalesce(findprev(occursin(bslash_separators), string, pos), 0) < slashpos && + slashpos = coalesce(findprev(isequal('\\'), string, pos), 0) + if (coalesce(findprev(in(bslash_separators), string, pos), 0) < slashpos && !(1 < slashpos && (string[prevind(string, slashpos)]=='\\'))) # latex / emoji symbol substitution s = string[slashpos:pos] @@ -543,8 +543,8 @@ function completions(string, pos) return String[], 0:-1, false end - dotpos = coalesce(findprev(equalto('.'), string, pos), 0) - startpos = nextind(string, coalesce(findprev(occursin(non_identifier_chars), string, pos), 0)) + dotpos = coalesce(findprev(isequal('.'), string, pos), 0) + startpos = nextind(string, coalesce(findprev(in(non_identifier_chars), string, pos), 0)) ffunc = (mod,x)->true suggestions = String[] diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 20cbdb7afd101..6af20641df60e 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -409,7 +409,7 @@ sub_1dim(S::SharedArray, pidx) = view(S.s, range_1dim(S, pidx)) function init_loc_flds(S::SharedArray{T,N}, empty_local=false) where T where N if myid() in S.pids - S.pidx = findfirst(equalto(myid()), S.pids) + S.pidx = findfirst(isequal(myid()), S.pids) if isa(S.refs[1], Future) refid = remoteref_id(S.refs[S.pidx]) else diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index 93fd8c912c1f9..4bb0faa7302c9 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -1954,7 +1954,7 @@ function sort(x::SparseVector{Tv,Ti}; kws...) where {Tv,Ti} allvals = push!(copy(nonzeros(x)),zero(Tv)) sinds = sortperm(allvals;kws...) n,k = length(x),length(allvals) - z = findfirst(equalto(k),sinds)::Int + z = findfirst(isequal(k),sinds)::Int newnzind = Vector{Ti}(1:k-1) newnzind[z:end] .+= n-k+1 newnzvals = allvals[deleteat!(sinds[1:k],z)] diff --git a/test/arrayops.jl b/test/arrayops.jl index 4bbc371d9203f..26045e4371aa6 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -291,34 +291,34 @@ end a = [3, 5, -7, 6] b = [4, 6, 2, -7, 1] - ind = findall(occursin(b), a) + ind = findall(in(b), a) @test ind == [3,4] - @test findall(occursin(Int[]), a) == Int[] - @test findall(occursin(a), Int[]) == Int[] + @test findall(in(Int[]), a) == Int[] + @test findall(in(a), Int[]) == Int[] a = [1,2,3,4,5] b = [2,3,4,6] - @test findall(occursin(b), a) == [2,3,4] - @test findall(occursin(a), b) == [1,2,3] - @test findall(occursin(Int[]), a) == Int[] - @test findall(occursin(a), Int[]) == Int[] + @test findall(in(b), a) == [2,3,4] + @test findall(in(a), b) == [1,2,3] + @test findall(in(Int[]), a) == Int[] + @test findall(in(a), Int[]) == Int[] a = Vector(1:3:15) b = Vector(2:4:10) - @test findall(occursin(b), a) == [4] - @test findall(occursin(b), [a[1:4]; a[4:end]]) == [4,5] + @test findall(in(b), a) == [4] + @test findall(in(b), [a[1:4]; a[4:end]]) == [4,5] - @test findall(occursin(NaN), [1.0, NaN, 2.0]) == [2] - @test findall(occursin(NaN), [1.0, 2.0, NaN]) == [3] + @test findall(in(NaN), [1.0, NaN, 2.0]) == [2] + @test findall(in(NaN), [1.0, 2.0, NaN]) == [3] - @testset "findall(::OccursIn, b) for uncomparable element types" begin + @testset "findall(in(x), b) for uncomparable element types" begin a = [1 + 1im, 1 - 1im] - @test findall(occursin(1 + 1im), a) == [1] - @test findall(occursin(a), a) == [1,2] + @test findall(in(1 + 1im), a) == [1] + @test findall(in(a), a) == [1,2] end - @test findall(occursin([1, 2]), 2) == [1] - @test findall(occursin([1, 2]), 3) == [] + @test findall(in([1, 2]), 2) == [1] + @test findall(in([1, 2]), 3) == [] rt = Base.return_types(setindex!, Tuple{Array{Int32, 3}, UInt8, Vector{Int}, Int16, UnitRange{Int}}) @test length(rt) == 1 && rt[1] == Array{Int32, 3} @@ -458,32 +458,32 @@ end @test findfirst(!iszero, a) == 2 @test findfirst(a.==0) == 1 @test findfirst(a.==5) == nothing - @test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6 - @test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2 + @test findfirst(isequal(3), [1,2,4,1,2,3,4]) == 6 + @test findfirst(!isequal(1), [1,2,4,1,2,3,4]) == 2 @test findfirst(isodd, [2,4,6,3,9,2,0]) == 4 @test findfirst(isodd, [2,4,6,2,0]) == nothing @test findnext(!iszero,a,4) == 4 @test findnext(!iszero,a,5) == 6 @test findnext(!iszero,a,1) == 2 - @test findnext(equalto(1),a,4) == 6 - @test findnext(equalto(5),a,4) == nothing + @test findnext(isequal(1),a,4) == 6 + @test findnext(isequal(5),a,4) == nothing @test findlast(!iszero, a) == 8 @test findlast(a.==0) == 5 @test findlast(a.==5) == nothing - @test findlast(equalto(3), [1,2,4,1,2,3,4]) == 6 + @test findlast(isequal(3), [1,2,4,1,2,3,4]) == 6 @test findlast(isodd, [2,4,6,3,9,2,0]) == 5 @test findlast(isodd, [2,4,6,2,0]) == nothing @test findprev(!iszero,a,4) == 4 @test findprev(!iszero,a,5) == 4 @test findprev(!iszero,a,1) == nothing - @test findprev(equalto(1),a,4) == 2 - @test findprev(equalto(1),a,8) == 6 + @test findprev(isequal(1),a,4) == 2 + @test findprev(isequal(1),a,8) == 6 @test findprev(isodd, [2,4,5,3,9,2,0], 7) == 5 @test findprev(isodd, [2,4,5,3,9,2,0], 2) == nothing - @test findfirst(equalto(0x00), [0x01, 0x00]) == 2 - @test findlast(equalto(0x00), [0x01, 0x00]) == 2 - @test findnext(equalto(0x00), [0x00, 0x01, 0x00], 2) == 3 - @test findprev(equalto(0x00), [0x00, 0x01, 0x00], 2) == 1 + @test findfirst(isequal(0x00), [0x01, 0x00]) == 2 + @test findlast(isequal(0x00), [0x01, 0x00]) == 2 + @test findnext(isequal(0x00), [0x00, 0x01, 0x00], 2) == 3 + @test findprev(isequal(0x00), [0x00, 0x01, 0x00], 2) == 1 end @testset "find with Matrix" begin A = [1 2 0; 3 4 0] @@ -1261,7 +1261,7 @@ end # logical indexing a = [1:10;]; acopy = copy(a) - @test deleteat!(a, map(occursin(idx), 1:length(a))) == [acopy[1:(first(idx)-1)]; acopy[(last(idx)+1):end]] + @test deleteat!(a, map(in(idx), 1:length(a))) == [acopy[1:(first(idx)-1)]; acopy[(last(idx)+1):end]] end a = [1:10;] @test deleteat!(a, 11:10) == [1:10;] diff --git a/test/bitarray.jl b/test/bitarray.jl index 22e20241db562..dea99ed0f6b4d 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1087,7 +1087,7 @@ timesofar("datamove") @check_bit_operation findfirst(!iszero, b1) Union{Int,Nothing} @check_bit_operation findfirst(iszero, b1) Union{Int,Nothing} - @check_bit_operation findfirst(equalto(3), b1) Union{Int,Nothing} + @check_bit_operation findfirst(isequal(3), b1) Union{Int,Nothing} @check_bit_operation findfirst(x->x, b1) Union{Int,Nothing} @check_bit_operation findfirst(x->!x, b1) Union{Int,Nothing} @@ -1120,7 +1120,7 @@ timesofar("find") b1 = trues(v1) b2 = falses(v1) for i = 1:v1 - @test findprev(b1, i) == findprev(equalto(true), b1, i) == findprev(identity, b1, i) + @test findprev(b1, i) == findprev(isequal(true), b1, i) == findprev(identity, b1, i) @test findprevnot(b2, i) == findprev(!, b2, i) == i end diff --git a/test/bitset.jl b/test/bitset.jl index b62ea9bacc1c8..1c4904162c444 100644 --- a/test/bitset.jl +++ b/test/bitset.jl @@ -8,7 +8,7 @@ using Random data_in = (1,5,100) s = BitSet(data_in) data_out = collect(s) - @test all(map(occursin(data_out), data_in)) + @test all(map(in(data_out), data_in)) @test length(data_out) === length(data_in) end diff --git a/test/choosetests.jl b/test/choosetests.jl index 49584c8d2c7a1..ddad7f6ad91f6 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -170,7 +170,7 @@ function choosetests(choices = []) end if !net_on - filter!(!occursin(net_required_for), tests) + filter!(!in(net_required_for), tests) end if ccall(:jl_running_on_valgrind,Cint,()) != 0 && "rounding" in tests @@ -181,7 +181,7 @@ function choosetests(choices = []) # The shift and invert solvers need SuiteSparse for sparse input Base.USE_GPL_LIBS || filter!(x->x != "IterativeEigensolvers", STDLIBS) - filter!(!occursin(skip_tests), tests) + filter!(!in(skip_tests), tests) tests, net_on, exit_on_error, seed end diff --git a/test/dict.jl b/test/dict.jl index a2264bbdade66..f67120c7add8f 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -906,15 +906,15 @@ end end @testset "find" begin - @test findall(equalto(1), Dict(:a=>1, :b=>2)) == [:a] - @test sort(findall(equalto(1), Dict(:a=>1, :b=>1))) == [:a, :b] - @test isempty(findall(equalto(1), Dict())) - @test isempty(findall(equalto(1), Dict(:a=>2, :b=>3))) - - @test findfirst(equalto(1), Dict(:a=>1, :b=>2)) == :a - @test findfirst(equalto(1), Dict(:a=>1, :b=>1, :c=>3)) in (:a, :b) - @test findfirst(equalto(1), Dict()) === nothing - @test findfirst(equalto(1), Dict(:a=>2, :b=>3)) === nothing + @test findall(isequal(1), Dict(:a=>1, :b=>2)) == [:a] + @test sort(findall(isequal(1), Dict(:a=>1, :b=>1))) == [:a, :b] + @test isempty(findall(isequal(1), Dict())) + @test isempty(findall(isequal(1), Dict(:a=>2, :b=>3))) + + @test findfirst(isequal(1), Dict(:a=>1, :b=>2)) == :a + @test findfirst(isequal(1), Dict(:a=>1, :b=>1, :c=>3)) in (:a, :b) + @test findfirst(isequal(1), Dict()) === nothing + @test findfirst(isequal(1), Dict(:a=>2, :b=>3)) === nothing end @testset "Dict printing with limited rows" begin diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 5dc2397506f43..a97591ee9a290 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,18 +209,18 @@ abstr_nt_22194_3() @test typeof(Base.structdiff(NamedTuple{(:a, :b), Tuple{Int32, Union{Int32, Nothing}}}((1, Int32(2))), (a=0,))) === NamedTuple{(:b,), Tuple{Union{Int32, Nothing}}} -@test findall(equalto(1), (a=1, b=2)) == [:a] -@test findall(equalto(1), (a=1, b=1)) == [:a, :b] -@test isempty(findall(equalto(1), NamedTuple())) -@test isempty(findall(equalto(1), (a=2, b=3))) -@test findfirst(equalto(1), (a=1, b=2)) == :a -@test findlast(equalto(1), (a=1, b=2)) == :a -@test findfirst(equalto(1), (a=1, b=1)) == :a -@test findlast(equalto(1), (a=1, b=1)) == :b -@test findfirst(equalto(1), ()) === nothing -@test findlast(equalto(1), ()) === nothing -@test findfirst(equalto(1), (a=2, b=3)) === nothing -@test findlast(equalto(1), (a=2, b=3)) === nothing +@test findall(isequal(1), (a=1, b=2)) == [:a] +@test findall(isequal(1), (a=1, b=1)) == [:a, :b] +@test isempty(findall(isequal(1), NamedTuple())) +@test isempty(findall(isequal(1), (a=2, b=3))) +@test findfirst(isequal(1), (a=1, b=2)) == :a +@test findlast(isequal(1), (a=1, b=2)) == :a +@test findfirst(isequal(1), (a=1, b=1)) == :a +@test findlast(isequal(1), (a=1, b=1)) == :b +@test findfirst(isequal(1), ()) === nothing +@test findlast(isequal(1), ()) === nothing +@test findfirst(isequal(1), (a=2, b=3)) === nothing +@test findlast(isequal(1), (a=2, b=3)) === nothing # Test map with Nothing and Missing for T in (Nothing, Missing) diff --git a/test/ranges.jl b/test/ranges.jl index 1ad6f1d93365f..f723112b49dfa 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -250,13 +250,13 @@ end @test length(1:2:0) == 0 end @testset "findall(::OccursIn, ::Array)" begin - @test findall(occursin(3:20), [5.2, 3.3]) == findall(occursin(Vector(3:20)), [5.2, 3.3]) + @test findall(in(3:20), [5.2, 3.3]) == findall(in(Vector(3:20)), [5.2, 3.3]) let span = 5:20, r = -7:3:42 - @test findall(occursin(span), r) == 5:10 + @test findall(in(span), r) == 5:10 r = 15:-2:-38 - @test findall(occursin(span), r) == 1:6 + @test findall(in(span), r) == 1:6 end end @testset "reverse" begin @@ -1109,16 +1109,16 @@ end @test intersect(r, Base.OneTo(2)) == Base.OneTo(2) @test intersect(r, 0:5) == 1:3 @test intersect(r, 2) === intersect(2, r) === 2:2 - @test findall(occursin(r), r) === findall(occursin(1:length(r)), r) === - findall(occursin(r), 1:length(r)) === 1:length(r) + @test findall(in(r), r) === findall(in(1:length(r)), r) === + findall(in(r), 1:length(r)) === 1:length(r) io = IOBuffer() show(io, r) str = String(take!(io)) @test str == "Base.OneTo(3)" end let r = Base.OneTo(7) - @test findall(occursin(2:(length(r) - 1)), r) === 2:(length(r) - 1) - @test findall(occursin(r), 2:(length(r) - 1)) === 1:(length(r) - 2) + @test findall(in(2:(length(r) - 1)), r) === 2:(length(r) - 1) + @test findall(in(r), 2:(length(r) - 1)) === 1:(length(r) - 2) end end diff --git a/test/runtests.jl b/test/runtests.jl index f4630e82b80b2..fd3870e06cee3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,7 +41,7 @@ end const node1_tests = String[] function move_to_node1(t) if t in tests - splice!(tests, findfirst(equalto(t), tests)) + splice!(tests, findfirst(isequal(t), tests)) push!(node1_tests, t) end end diff --git a/test/sets.jl b/test/sets.jl index 8e1dc64a86269..320cc5f212b04 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -11,7 +11,7 @@ using .Main.TestHelpers.OAs s = Set(data_in) data_out = collect(s) @test ===(typeof(data_out), Array{Any,1}) - @test all(map(occursin(data_out), data_in)) + @test all(map(in(data_out), data_in)) @test length(data_out) == length(data_in) let f17741 = x -> x < 0 ? false : 1 @test isa(Set(x for x = 1:3), Set{Int}) diff --git a/test/strings/search.jl b/test/strings/search.jl index f3384228a9f46..7c1427bce4b11 100644 --- a/test/strings/search.jl +++ b/test/strings/search.jl @@ -14,104 +14,104 @@ end # Note: the commented out test will be enabled after fixes to make # sure that findnext/findprev are consistent # no matter what type of AbstractString the second argument is -@test_throws BoundsError findnext(equalto('a'), "foo", 0) -@test_throws BoundsError findnext(occursin(Char[]), "foo", 5) -# @test_throws BoundsError findprev(occursin(Char[]), "foo", 0) -@test_throws BoundsError findprev(occursin(Char[]), "foo", 5) +@test_throws BoundsError findnext(isequal('a'), "foo", 0) +@test_throws BoundsError findnext(in(Char[]), "foo", 5) +# @test_throws BoundsError findprev(in(Char[]), "foo", 0) +@test_throws BoundsError findprev(in(Char[]), "foo", 5) # @test_throws ErrorException in("foobar","bar") -@test_throws BoundsError findnext(equalto(0x1),b"\x1\x2",0) +@test_throws BoundsError findnext(isequal(0x1),b"\x1\x2",0) # ascii forward search for str in [astr, GenericString(astr)] - @test_throws BoundsError findnext(equalto('z'), str, 0) - @test_throws BoundsError findnext(equalto('∀'), str, 0) - @test findfirst(equalto('x'), str) == nothing - @test findfirst(equalto('\0'), str) == nothing - @test findfirst(equalto('\u80'), str) == nothing - @test findfirst(equalto('∀'), str) == nothing - @test findfirst(equalto('H'), str) == 1 - @test findfirst(equalto('l'), str) == 3 - @test findnext(equalto('l'), str, 4) == 4 - @test findnext(equalto('l'), str, 5) == 11 - @test findnext(equalto('l'), str, 12) == nothing - @test findfirst(equalto(','), str) == 6 - @test findnext(equalto(','), str, 7) == nothing - @test findfirst(equalto('\n'), str) == 14 - @test findnext(equalto('\n'), str, 15) == nothing - @test_throws BoundsError findnext(equalto('ε'), str, nextind(str,lastindex(str))+1) - @test_throws BoundsError findnext(equalto('a'), str, nextind(str,lastindex(str))+1) + @test_throws BoundsError findnext(isequal('z'), str, 0) + @test_throws BoundsError findnext(isequal('∀'), str, 0) + @test findfirst(isequal('x'), str) == nothing + @test findfirst(isequal('\0'), str) == nothing + @test findfirst(isequal('\u80'), str) == nothing + @test findfirst(isequal('∀'), str) == nothing + @test findfirst(isequal('H'), str) == 1 + @test findfirst(isequal('l'), str) == 3 + @test findnext(isequal('l'), str, 4) == 4 + @test findnext(isequal('l'), str, 5) == 11 + @test findnext(isequal('l'), str, 12) == nothing + @test findfirst(isequal(','), str) == 6 + @test findnext(isequal(','), str, 7) == nothing + @test findfirst(isequal('\n'), str) == 14 + @test findnext(isequal('\n'), str, 15) == nothing + @test_throws BoundsError findnext(isequal('ε'), str, nextind(str,lastindex(str))+1) + @test_throws BoundsError findnext(isequal('a'), str, nextind(str,lastindex(str))+1) end # ascii backward search for str in [astr] - @test findlast(equalto('x'), str) == nothing - @test findlast(equalto('\0'), str) == nothing - @test findlast(equalto('\u80'), str) == nothing - @test findlast(equalto('∀'), str) == nothing - @test findlast(equalto('H'), str) == 1 - @test findprev(equalto('H'), str, 0) == nothing - @test findlast(equalto('l'), str) == 11 - @test findprev(equalto('l'), str, 5) == 4 - @test findprev(equalto('l'), str, 4) == 4 - @test findprev(equalto('l'), str, 3) == 3 - @test findprev(equalto('l'), str, 2) == nothing - @test findlast(equalto(','), str) == 6 - @test findprev(equalto(','), str, 5) == nothing - @test findlast(equalto('\n'), str) == 14 + @test findlast(isequal('x'), str) == nothing + @test findlast(isequal('\0'), str) == nothing + @test findlast(isequal('\u80'), str) == nothing + @test findlast(isequal('∀'), str) == nothing + @test findlast(isequal('H'), str) == 1 + @test findprev(isequal('H'), str, 0) == nothing + @test findlast(isequal('l'), str) == 11 + @test findprev(isequal('l'), str, 5) == 4 + @test findprev(isequal('l'), str, 4) == 4 + @test findprev(isequal('l'), str, 3) == 3 + @test findprev(isequal('l'), str, 2) == nothing + @test findlast(isequal(','), str) == 6 + @test findprev(isequal(','), str, 5) == nothing + @test findlast(isequal('\n'), str) == 14 end # utf-8 forward search for str in (u8str, GenericString(u8str)) - @test_throws BoundsError findnext(equalto('z'), str, 0) - @test_throws BoundsError findnext(equalto('∀'), str, 0) - @test findfirst(equalto('z'), str) == nothing - @test findfirst(equalto('\0'), str) == nothing - @test findfirst(equalto('\u80'), str) == nothing - @test findfirst(equalto('∄'), str) == nothing - @test findfirst(equalto('∀'), str) == 1 - @test_throws StringIndexError findnext(equalto('∀'), str, 2) - @test findnext(equalto('∀'), str, 4) == nothing - @test findfirst(equalto('∃'), str) == 13 - @test_throws StringIndexError findnext(equalto('∃'), str, 15) - @test findnext(equalto('∃'), str, 16) == nothing - @test findfirst(equalto('x'), str) == 26 - @test findnext(equalto('x'), str, 27) == 43 - @test findnext(equalto('x'), str, 44) == nothing - @test findfirst(equalto('δ'), str) == 17 - @test_throws StringIndexError findnext(equalto('δ'), str, 18) - @test findnext(equalto('δ'), str, nextind(str,17)) == 33 - @test findnext(equalto('δ'), str, nextind(str,33)) == nothing - @test findfirst(equalto('ε'), str) == 5 - @test findnext(equalto('ε'), str, nextind(str,5)) == 54 - @test findnext(equalto('ε'), str, nextind(str,54)) == nothing - @test findnext(equalto('ε'), str, nextind(str,lastindex(str))) == nothing - @test findnext(equalto('a'), str, nextind(str,lastindex(str))) == nothing - @test_throws BoundsError findnext(equalto('ε'), str, nextind(str,lastindex(str))+1) - @test_throws BoundsError findnext(equalto('a'), str, nextind(str,lastindex(str))+1) + @test_throws BoundsError findnext(isequal('z'), str, 0) + @test_throws BoundsError findnext(isequal('∀'), str, 0) + @test findfirst(isequal('z'), str) == nothing + @test findfirst(isequal('\0'), str) == nothing + @test findfirst(isequal('\u80'), str) == nothing + @test findfirst(isequal('∄'), str) == nothing + @test findfirst(isequal('∀'), str) == 1 + @test_throws StringIndexError findnext(isequal('∀'), str, 2) + @test findnext(isequal('∀'), str, 4) == nothing + @test findfirst(isequal('∃'), str) == 13 + @test_throws StringIndexError findnext(isequal('∃'), str, 15) + @test findnext(isequal('∃'), str, 16) == nothing + @test findfirst(isequal('x'), str) == 26 + @test findnext(isequal('x'), str, 27) == 43 + @test findnext(isequal('x'), str, 44) == nothing + @test findfirst(isequal('δ'), str) == 17 + @test_throws StringIndexError findnext(isequal('δ'), str, 18) + @test findnext(isequal('δ'), str, nextind(str,17)) == 33 + @test findnext(isequal('δ'), str, nextind(str,33)) == nothing + @test findfirst(isequal('ε'), str) == 5 + @test findnext(isequal('ε'), str, nextind(str,5)) == 54 + @test findnext(isequal('ε'), str, nextind(str,54)) == nothing + @test findnext(isequal('ε'), str, nextind(str,lastindex(str))) == nothing + @test findnext(isequal('a'), str, nextind(str,lastindex(str))) == nothing + @test_throws BoundsError findnext(isequal('ε'), str, nextind(str,lastindex(str))+1) + @test_throws BoundsError findnext(isequal('a'), str, nextind(str,lastindex(str))+1) end # utf-8 backward search for str in [u8str] - @test findlast(equalto('z'), str) == nothing - @test findlast(equalto('\0'), str) == nothing - @test findlast(equalto('\u80'), str) == nothing - @test findlast(equalto('∄'), str) == nothing - @test findlast(equalto('∀'), str) == 1 - @test findprev(equalto('∀'), str, 0) == nothing - @test findlast(equalto('∃'), str) == 13 - @test findprev(equalto('∃'), str, 14) == 13 - @test findprev(equalto('∃'), str, 13) == 13 - @test findprev(equalto('∃'), str, 12) == nothing - @test findlast(equalto('x'), str) == 43 - @test findprev(equalto('x'), str, 42) == 26 - @test findprev(equalto('x'), str, 25) == nothing - @test findlast(equalto('δ'), str) == 33 - @test findprev(equalto('δ'), str, 32) == 17 - @test findprev(equalto('δ'), str, 16) == nothing - @test findlast(equalto('ε'), str) == 54 - @test findprev(equalto('ε'), str, 53) == 5 - @test findprev(equalto('ε'), str, 4) == nothing + @test findlast(isequal('z'), str) == nothing + @test findlast(isequal('\0'), str) == nothing + @test findlast(isequal('\u80'), str) == nothing + @test findlast(isequal('∄'), str) == nothing + @test findlast(isequal('∀'), str) == 1 + @test findprev(isequal('∀'), str, 0) == nothing + @test findlast(isequal('∃'), str) == 13 + @test findprev(isequal('∃'), str, 14) == 13 + @test findprev(isequal('∃'), str, 13) == 13 + @test findprev(isequal('∃'), str, 12) == nothing + @test findlast(isequal('x'), str) == 43 + @test findprev(isequal('x'), str, 42) == 26 + @test findprev(isequal('x'), str, 25) == nothing + @test findlast(isequal('δ'), str) == 33 + @test findprev(isequal('δ'), str, 32) == 17 + @test findprev(isequal('δ'), str, 16) == nothing + @test findlast(isequal('ε'), str) == 54 + @test findprev(isequal('ε'), str, 53) == 5 + @test findprev(isequal('ε'), str, 4) == nothing end # string forward search with a single-char string @@ -320,11 +320,11 @@ end @test_throws ErrorException "ab" ∈ "abc" # issue #15723 -@test findfirst(equalto('('), "⨳(") == 4 -@test findnext(equalto('('), "(⨳(", 2) == 5 -@test findlast(equalto('('), "(⨳(") == 5 -@test findprev(equalto('('), "(⨳(", 2) == 1 +@test findfirst(isequal('('), "⨳(") == 4 +@test findnext(isequal('('), "(⨳(", 2) == 5 +@test findlast(isequal('('), "(⨳(") == 5 +@test findprev(isequal('('), "(⨳(", 2) == 1 -@test @inferred findall(equalto('a'), "éa") == [3] -@test @inferred findall(equalto('€'), "€€") == [1, 4] -@test @inferred isempty(findall(equalto('é'), "")) \ No newline at end of file +@test @inferred findall(isequal('a'), "éa") == [3] +@test @inferred findall(isequal('€'), "€€") == [1, 4] +@test @inferred isempty(findall(isequal('é'), "")) diff --git a/test/strings/types.jl b/test/strings/types.jl index 634e7d8eb973a..c5679ddd55b7b 100644 --- a/test/strings/types.jl +++ b/test/strings/types.jl @@ -119,7 +119,7 @@ end let str = "Hello, world!" u = SubString(str, 1, 5) @test findlast("World", u) == nothing - @test findlast(equalto('z'), u) == nothing + @test findlast(isequal('z'), u) == nothing @test findlast("ll", u) == 3:4 end @@ -274,14 +274,14 @@ end for c in ('X', 'δ', '\U0001d6a5') s = convert(T, string(prefix, c, suffix)) r = reverse(s) - ri = findfirst(equalto(c), r) + ri = findfirst(isequal(c), r) @test c == s[reverseind(s, ri)] == r[ri] s = convert(T, string(prefix, prefix, c, suffix, suffix)) pre = convert(T, prefix) sb = SubString(s, nextind(pre, lastindex(pre)), lastindex(convert(T, string(prefix, prefix, c, suffix)))) r = reverse(sb) - ri = findfirst(equalto(c), r) + ri = findfirst(isequal(c), r) @test c == sb[reverseind(sb, ri)] == r[ri] end end diff --git a/test/strings/util.jl b/test/strings/util.jl index 9f3b2d6d00c01..5014475d16db9 100644 --- a/test/strings/util.jl +++ b/test/strings/util.jl @@ -273,7 +273,7 @@ end @test replace("a", "a" => typeof) == "SubString{String}" @test replace("a", r"a" => typeof) == "SubString{String}" @test replace("a", 'a' => typeof) == "Char" - @test replace("a", occursin("a") => typeof) == "Char" + @test replace("a", in("a") => typeof) == "Char" @test replace("a", ['a'] => typeof) == "Char" end diff --git a/test/tuple.jl b/test/tuple.jl index 3afdbbc6e651b..e16d2acf1be3a 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -405,24 +405,24 @@ end end @testset "find" begin - @test findall(equalto(1), (1, 2)) == [1] - @test findall(equalto(1), (1, 1)) == [1, 2] - @test isempty(findall(equalto(1), ())) - @test isempty(findall(equalto(1), (2, 3))) - - @test findfirst(equalto(1), (1, 2)) == 1 - @test findlast(equalto(1), (1, 2)) == 1 - @test findfirst(equalto(1), (1, 1)) == 1 - @test findlast(equalto(1), (1, 1)) == 2 - @test findfirst(equalto(1), ()) === nothing - @test findlast(equalto(1), ()) === nothing - @test findfirst(equalto(1), (2, 3)) === nothing - @test findlast(equalto(1), (2, 3)) === nothing - - @test findnext(equalto(1), (1, 2), 1) == 1 - @test findprev(equalto(1), (1, 2), 2) == 1 - @test findnext(equalto(1), (1, 1), 2) == 2 - @test findprev(equalto(1), (1, 1), 1) == 1 - @test findnext(equalto(1), (2, 3), 1) === nothing - @test findprev(equalto(1), (2, 3), 2) === nothing + @test findall(isequal(1), (1, 2)) == [1] + @test findall(isequal(1), (1, 1)) == [1, 2] + @test isempty(findall(isequal(1), ())) + @test isempty(findall(isequal(1), (2, 3))) + + @test findfirst(isequal(1), (1, 2)) == 1 + @test findlast(isequal(1), (1, 2)) == 1 + @test findfirst(isequal(1), (1, 1)) == 1 + @test findlast(isequal(1), (1, 1)) == 2 + @test findfirst(isequal(1), ()) === nothing + @test findlast(isequal(1), ()) === nothing + @test findfirst(isequal(1), (2, 3)) === nothing + @test findlast(isequal(1), (2, 3)) === nothing + + @test findnext(isequal(1), (1, 2), 1) == 1 + @test findprev(isequal(1), (1, 2), 2) == 1 + @test findnext(isequal(1), (1, 1), 2) == 2 + @test findprev(isequal(1), (1, 1), 1) == 1 + @test findnext(isequal(1), (2, 3), 1) === nothing + @test findprev(isequal(1), (2, 3), 2) === nothing end