Browse Source

Fix display bug of abstract type EnumX.Enum.

pull/8/head v1.0.1
Fredrik Ekre 4 years ago
parent
commit
e5f1753020
  1. 2
      Project.toml
  2. 6
      src/EnumX.jl
  3. 6
      test/runtests.jl

2
Project.toml

@ -1,6 +1,6 @@
name = "EnumX" name = "EnumX"
uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56" uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
version = "1.0.0" version = "1.0.1"
[compat] [compat]
julia = "1.6" julia = "1.6"

6
src/EnumX.jl

@ -138,7 +138,11 @@ function Base.show(io::IO, ::MIME"text/plain", x::E) where E <: Enum
write(io, seekstart(iob)) write(io, seekstart(iob))
return nothing return nothing
end end
function Base.show(io::IO, ::MIME"text/plain", ::Base.Type{E}) where E <: Enum function Base.show(io::IO, ::MIME"text/plain", ::Type{E}) where E <: Enum
if !isconcretetype(E) # handle EnumX.Enum and EnumX.Enum{T}
invoke(show, Tuple{IO, Type}, io, E)
return
end
iob = IOBuffer() iob = IOBuffer()
insts = Base.Enums.instances(E) insts = Base.Enums.instances(E)
n = length(insts) n = length(insts)

6
test/runtests.jl

@ -71,6 +71,12 @@ let io = IOBuffer()
show(io, "text/plain", Fruit.Banana) show(io, "text/plain", Fruit.Banana)
str = String(take!(io)) str = String(take!(io))
@test str == "Fruit.Banana = 1" @test str == "Fruit.Banana = 1"
show(io, "text/plain", EnumX.Enum)
str = String(take!(io))
@test str == "EnumX.Enum"
show(io, "text/plain", EnumX.Enum{Int32})
str = String(take!(io))
@test str == "EnumX.Enum{Int32}"
end end

Loading…
Cancel
Save