Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contains(haystack, needle) -> occursin(needle, haystack) #55

Merged
merged 3 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 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 Expand Up @@ -301,6 +301,8 @@ on TravisCI as well.
"""
url(m::Method) = url(m.module, string(m.file), m.line)

import Compat.LibGit2

function url(mod::Module, file::AbstractString, line::Integer)
file = Compat.Sys.iswindows() ? replace(file, '\\', '/') : file
if Base.inbase(mod) && !isabspath(file)
Expand Down
102 changes: 52 additions & 50 deletions test/tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

using Compat

const DSE = DocStringExtensions

include("templates.jl")
Expand Down Expand Up @@ -73,7 +75,7 @@ end
@test isa(methods(M.j_1), Base.MethodList)
@test isdefined(methods(M.j_1), :mt)
local mt = methods(M.j_1).mt
@test isa(mt, Base.MethodTable)
@test isa(mt, Core.MethodTable)
@test isdefined(mt, :kwsorter)
# .kwsorter is not always defined -- namely, it seems when none of the methods
# have keyword arguments:
Expand Down Expand Up @@ -107,13 +109,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 +128,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 +143,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 +156,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 +167,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 +179,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 +195,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 +206,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 +217,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 +228,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