Skip to content

Commit

Permalink
Merge pull request #58 from JuliaDocs/backports-0.4.4
Browse files Browse the repository at this point in the history
Backports for 0.4.4
  • Loading branch information
mortenpi authored Mar 27, 2018
2 parents 73fc332 + 897e0ef commit cc83610
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 57 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.33 # Compat.Test
Compat 0.62
4 changes: 2 additions & 2 deletions src/abbreviations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function format(::TypeFields, buf, doc)
# On 0.7 fieldnames() on an abstract type throws an error. We then explicitly return
# an empty vector to be consistent with the behaviour on v0.6.
# Compat necessary since Base.isabstract was introduced in v0.6.
local fields = Compat.TypeUtils.isabstract(object) ? Symbol[] : fieldnames(object)
local fields = isabstracttype(object) ? Symbol[] : fieldnames(object)
if !isempty(fields)
println(buf)
for field in fields
Expand Down Expand Up @@ -136,7 +136,7 @@ function format(::ModuleExports, buf, doc)
# Sorting ignores the `@` in macro names and sorts them in with others.
for sym in sort(exports, by = s -> lstrip(string(s), '@'))
# Skip the module itself, since that's always exported.
sym === module_name(object) && continue
sym === nameof(object) && continue
# We print linked names using Documenter.jl cross-reference syntax
# for ease of integration with that package.
println(buf, " - [`", sym, "`](@ref)")
Expand Down
8 changes: 5 additions & 3 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ $(:SIGNATURES)
Is the type `t` a `bitstype`?
"""
isbitstype(@nospecialize(t)) = isconcrete(t) && sizeof(t) > 0 && isbits(t)
isbitstype(@nospecialize(t)) = isconcretetype(t) && sizeof(t) > 0 && isbits(t)

"""
$(:SIGNATURES)
Expand Down Expand Up @@ -169,7 +169,7 @@ $(:SIGNATURES)
Remove the `Pkg.dir` part of a file `path` if it exists.
"""
function cleanpath(path::AbstractString)
local pkgdir = joinpath(Pkg.dir(), "")
local pkgdir = joinpath(Compat.Pkg.dir(), "")
return startswith(path, pkgdir) ? first(split(path, pkgdir; keep = false)) : path
end

Expand Down 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
104 changes: 53 additions & 51 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)")
let fmt = expr -> Compat.Markdown.plain(eval(:(@doc $expr)))
@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 cc83610

Please sign in to comment.