Skip to content

Commit

Permalink
Fix #93.
Browse files Browse the repository at this point in the history
Changes tuple comparision from a roundabout string comparision to use
proper subtype comparision.

Also adjusts test cases to avoid triggering type alias printing such as
`Array{T,1}` to `Vector{T}` which fails on Julia 1.6.
  • Loading branch information
MichaelHatherly committed Aug 10, 2020
1 parent 254ba1c commit c016667
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/abbreviations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ function format(::TypedMethodSignatures, buf, doc)
# ideally we would check that the method signature matches the Tuple{...} signature
# but that is not straightforward because of how expressive Julia can be
if Sys.iswindows()
t = tuples[findlast(t -> t isa DataType && string(t.name) == "Tuple" && length(t.types) == N, tuples)]
t = tuples[findlast(t -> t isa DataType && t <: Tuple && length(t.types) == N, tuples)]
else
t = tuples[findfirst(t -> t isa DataType && string(t.name) == "Tuple" && length(t.types) == N, tuples)]
t = tuples[findfirst(t -> t isa DataType && t <: Tuple && length(t.types) == N, tuples)]
end
printmethod(buf, binding, func, method, t)
println(buf)
Expand Down
4 changes: 2 additions & 2 deletions test/TestModule/M.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ g(x = 1, y = 2, z = 3; kwargs...) = x

h(x::Int, y::Int = 2, z::Int = 3; kwargs...) = x

const A{T} = Union{Vector{T}, Matrix{T}}
const A{T} = Union{Array{T, 3}, Array{T, 4}}

h_1(x::A) = x
h_2(x::A{Int}) = x
Expand All @@ -29,7 +29,7 @@ k_3(x, y::T, z::U) where {T, U} = x + y + z
k_4(::String, ::Int = 0) = nothing
k_5(::Type{T}, x::String, func::Union{Nothing, Function} = nothing) where T <: Number = x
k_6(x::Vector{T}) where T <: Number = x
k_7(x::Union{T,Nothing}, y::T = zero(T)) where {T <: Number} = x
k_7(x::Union{T,Nothing}, y::T = zero(T)) where {T <: Integer} = x
k_8(x) = x
k_9(x::T where T<:Any) = x
k_10(x::T) where T = x
Expand Down
14 changes: 7 additions & 7 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ end
str = String(take!(buf))
@test occursin("\n```julia\n", str)
if Sys.iswindows()
@test occursin("h_1(x::Union{Array{T,2}, Array{T,1}} where T) -> Union{Array{T,2}, Array{T,1}} where T", str)
@test occursin("h_1(x::Union{Array{T,4}, Array{T,3}} where T) -> Union{Array{T,4}, Array{T,3}} where T", str)
else
@test occursin("h_1(x::Union{Array{T,1}, Array{T,2}} where T) -> Union{Array{T,1}, Array{T,2}} where T", str)
@test occursin("h_1(x::Union{Array{T,3}, Array{T,4}} where T) -> Union{Array{T,3}, Array{T,4}} where T", str)
end
@test occursin("\n```\n", str)

Expand Down Expand Up @@ -316,14 +316,14 @@ end

doc.data = Dict(
:binding => Docs.Binding(M, :k_7),
:typesig => Union{Tuple{Union{T, Nothing}}, Tuple{Union{T, Nothing}, T}, Tuple{T}} where T <: Number,
:typesig => Union{Tuple{Union{T, Nothing}}, Tuple{Union{T, Nothing}, T}, Tuple{T}} where T <: Integer,
:module => M,
)
DSE.format(DSE.TYPEDSIGNATURES, buf, doc)
str = String(take!(buf))
@test occursin("\n```julia\n", str)
@test occursin("\nk_7(x::Union{Nothing, T<:Number}) -> Union{Nothing, Number}\n", str)
@test occursin("\nk_7(x::Union{Nothing, T<:Number}, y::T<:Number) -> Union{Nothing, T<:Number}\n", str)
@test occursin("\nk_7(x::Union{Nothing, T<:Integer}) -> Union{Nothing, Integer}\n", str)
@test occursin("\nk_7(x::Union{Nothing, T<:Integer}, y::T<:Integer) -> Union{Nothing, T<:Integer}\n", str)
@test occursin("\n```\n", str)

doc.data = Dict(
Expand Down Expand Up @@ -553,8 +553,8 @@ end
@test length(DSE.getmethods(M.f, Tuple{})) == 0
@test length(DSE.getmethods(M.f, Union{Tuple{}, Tuple{Any}})) == 1
@test length(DSE.getmethods(M.h_3, Tuple{M.A{Int}})) == 1
@test length(DSE.getmethods(M.h_3, Tuple{Vector{Int}})) == 1
@test length(DSE.getmethods(M.h_3, Tuple{Array{Int, 3}})) == 0
@test length(DSE.getmethods(M.h_3, Tuple{Array{Int, 3}})) == 1
@test length(DSE.getmethods(M.h_3, Tuple{Array{Int, 1}})) == 0
end
@testset "methodgroups" begin
@test length(DSE.methodgroups(M.f, Tuple{Any}, M)) == 1
Expand Down

0 comments on commit c016667

Please sign in to comment.