Skip to content

Commit

Permalink
contains(haystack, needle) -> occursin(needle, haystack)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Mar 21, 2018
1 parent 67b2db7 commit e0e3489
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.6
Compat 0.50 # isabstracttype / isconcretetype / nameof
Compat 0.62
2 changes: 1 addition & 1 deletion src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function keywords(func, m::Method)
# Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0):
local kwargs = Base.kwarg_decl(m, typeof(table.kwsorter))
if isa(kwargs, Vector) && length(kwargs) > 0
filter!(arg -> !contains(string(arg), "#"), kwargs)
filter!(arg -> !occursin("#", string(arg)), kwargs)
# Keywords *may* not be sorted correctly. We move the vararg one to the end.
local index = findfirst(arg -> endswith(string(arg), "..."), kwargs)
if index != nothing && index > 0 # TODO: use Compat.findfirst later on
Expand Down
98 changes: 49 additions & 49 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ end
)
DSE.format(IMPORTS, buf, doc)
str = String(take!(buf))
@test contains(str, "\n - `Base`\n")
@test contains(str, "\n - `Core`\n")
@test occursin("\n - `Base`\n", str)
@test occursin("\n - `Core`\n", str)

# Module exports.
DSE.format(EXPORTS, buf, doc)
str = String(take!(buf))
@test contains(str, "\n - [`f`](@ref)\n")
@test occursin("\n - [`f`](@ref)\n", str)
end

@testset "type fields" begin
Expand All @@ -126,11 +126,11 @@ end
)
DSE.format(FIELDS, buf, doc)
str = String(take!(buf))
@test contains(str, " - `a`")
@test contains(str, " - `b`")
@test contains(str, " - `c`")
@test contains(str, "one")
@test contains(str, "two")
@test occursin(" - `a`", str)
@test occursin(" - `b`", str)
@test occursin(" - `c`", str)
@test occursin("one", str)
@test occursin("two", str)
end

@testset "method lists" begin
Expand All @@ -141,9 +141,9 @@ end
)
DSE.format(METHODLIST, buf, doc)
str = String(take!(buf))
@test contains(str, "```julia")
@test contains(str, "f(x)")
@test contains(str, "[`$(joinpath("DocStringExtensions", "test", "tests.jl"))")
@test occursin("```julia", str)
@test occursin("f(x)", str)
@test occursin("[`$(joinpath("DocStringExtensions", "test", "tests.jl"))", str)
end

@testset "method signatures" begin
Expand All @@ -154,9 +154,9 @@ end
)
DSE.format(SIGNATURES, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\nf(x)\n")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\nf(x)\n", str)
@test occursin("\n```\n", str)

doc.data = Dict(
:binding => Docs.Binding(M, :g),
Expand All @@ -165,10 +165,10 @@ end
)
DSE.format(SIGNATURES, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\ng()\n")
@test contains(str, "\ng(x)\n")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\ng()\n", str)
@test occursin("\ng(x)\n", str)
@test occursin("\n```\n", str)

doc.data = Dict(
:binding => Docs.Binding(M, :g),
Expand All @@ -177,12 +177,12 @@ end
)
DSE.format(SIGNATURES, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\ng()\n")
@test contains(str, "\ng(x)\n")
@test contains(str, "\ng(x, y)\n")
@test contains(str, "\ng(x, y, z; kwargs...)\n")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\ng()\n", str)
@test occursin("\ng(x)\n", str)
@test occursin("\ng(x, y)\n", str)
@test occursin("\ng(x, y, z; kwargs...)\n", str)
@test occursin("\n```\n", str)
end

@testset "type definitions" begin
Expand All @@ -193,9 +193,9 @@ end
)
DSE.format(TYPEDEF, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\nabstract AbstractType <: Integer\n")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\nabstract AbstractType <: Integer\n", str)
@test occursin("\n```\n", str)

doc.data = Dict(
:binding => Docs.Binding(M, :CustomType),
Expand All @@ -204,9 +204,9 @@ end
)
DSE.format(TYPEDEF, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\nstruct CustomType{S, T<:Integer} <: Integer\n")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\nstruct CustomType{S, T<:Integer} <: Integer\n", str)
@test occursin("\n```\n", str)

doc.data = Dict(
:binding => Docs.Binding(M, :BitType8),
Expand All @@ -215,9 +215,9 @@ end
)
DSE.format(TYPEDEF, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\nbitstype 8 BitType8\n")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\nbitstype 8 BitType8\n", str)
@test occursin("\n```\n", str)

doc.data = Dict(
:binding => Docs.Binding(M, :BitType32),
Expand All @@ -226,26 +226,26 @@ end
)
DSE.format(TYPEDEF, buf, doc)
str = String(take!(buf))
@test contains(str, "\n```julia\n")
@test contains(str, "\nbitstype 32 BitType32 <: Real")
@test contains(str, "\n```\n")
@test occursin("\n```julia\n", str)
@test occursin("\nbitstype 32 BitType32 <: Real", str)
@test occursin("\n```\n", str)
end
end
@testset "templates" begin
let fmt = expr -> Markdown.plain(eval(:(@doc $expr)))
@test contains(fmt(:(TemplateTests.K)), "(DEFAULT)")
@test contains(fmt(:(TemplateTests.T)), "(TYPES)")
@test contains(fmt(:(TemplateTests.f)), "(METHODS, MACROS)")
@test contains(fmt(:(TemplateTests.g)), "(METHODS, MACROS)")
@test contains(fmt(:(TemplateTests.@m)), "(METHODS, MACROS)")

@test contains(fmt(:(TemplateTests.InnerModule.K)), "(DEFAULT)")
@test contains(fmt(:(TemplateTests.InnerModule.T)), "(DEFAULT)")
@test contains(fmt(:(TemplateTests.InnerModule.f)), "(METHODS, MACROS)")
@test contains(fmt(:(TemplateTests.InnerModule.@m)), "(MACROS)")

@test contains(fmt(:(TemplateTests.OtherModule.T)), "(TYPES)")
@test contains(fmt(:(TemplateTests.OtherModule.@m)), "(MACROS)")
@test occursin("(DEFAULT)", fmt(:(TemplateTests.K)))
@test occursin("(TYPES)", fmt(:(TemplateTests.T)))
@test occursin("(METHODS, MACROS)", fmt(:(TemplateTests.f)))
@test occursin("(METHODS, MACROS)", fmt(:(TemplateTests.g)))
@test occursin("(METHODS, MACROS)", fmt(:(TemplateTests.@m)))

@test occursin("(DEFAULT)", fmt(:(TemplateTests.InnerModule.K)))
@test occursin("(DEFAULT)", fmt(:(TemplateTests.InnerModule.T)))
@test occursin("(METHODS, MACROS)", fmt(:(TemplateTests.InnerModule.f)))
@test occursin("(MACROS)", fmt(:(TemplateTests.InnerModule.@m)))

@test occursin("(TYPES)", fmt(:(TemplateTests.OtherModule.T)))
@test occursin("(MACROS)", fmt(:(TemplateTests.OtherModule.@m)))
@test fmt(:(TemplateTests.OtherModule.f)) == "method `f`\n"
end
end
Expand Down

0 comments on commit e0e3489

Please sign in to comment.