diff --git a/Project.toml b/Project.toml index dedde07..bb9768b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "EnumX" uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56" -version = "1.0.3" +version = "1.0.4" [compat] julia = "1.6" diff --git a/src/EnumX.jl b/src/EnumX.jl index a466896..a6dc914 100644 --- a/src/EnumX.jl +++ b/src/EnumX.jl @@ -151,11 +151,16 @@ end function Base.show(io::IO, ::MIME"text/plain", x::E) where E <: Enum iob = IOBuffer() ix = Integer(x) + found = false for (k, v) in symbol_map(E) if v == ix print(iob, "$(nameof(parentmodule(E))).$(k) = ") + found = true end end + if !found + print(iob, "$(nameof(parentmodule(E))).#invalid# = ") + end show(iob, ix) write(io, seekstart(iob)) return nothing diff --git a/test/runtests.jl b/test/runtests.jl index 09750b9..ecf4664 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -266,6 +266,16 @@ end @test instances(FruitEmptyT.Typ) == () +# Showing invalid instances +@enumx Invalid A +let io = IOBuffer() + invalid = Base.bitcast(Invalid.T, Int32(1)) + show(io, "text/plain", invalid) + str = String(take!(io)) + @test str == "Invalid.#invalid# = 1" +end + + # Documented type (module) and instances begin """