diff --git a/Project.toml b/Project.toml index c2a552c..e0ab8e6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "EnumX" uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56" -version = "1.0.1" +version = "1.0.2" [compat] julia = "1.6" diff --git a/src/EnumX.jl b/src/EnumX.jl index 51c0d98..9310b01 100644 --- a/src/EnumX.jl +++ b/src/EnumX.jl @@ -134,7 +134,7 @@ function Base.show(io::IO, ::MIME"text/plain", x::E) where E <: Enum print(iob, "$(nameof(parentmodule(E))).$(k) = ") end end - print(iob, "$(Integer(x))") + show(iob, ix) write(io, seekstart(iob)) return nothing end @@ -155,7 +155,8 @@ function Base.show(io::IO, ::MIME"text/plain", ::Type{E}) where E <: Enum "Enum{$(Base.Enums.basetype(E))} with $(n) instance$(n == 1 ? "" : "s")$(n>0 ? ":" : "")" ) for (k, v) in stringmap - print(iob, "\n ", rpad(k, mx), " = $(v)") + print(iob, "\n ", rpad(k, mx), " = ") + show(iob, v) end write(io, seekstart(iob)) return nothing diff --git a/test/runtests.jl b/test/runtests.jl index 243d701..09750b9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -86,10 +86,22 @@ end @test Base.Enums.basetype(Fruit8.T) === Int8 @test Integer(Fruit8.Apple) === Int8(0) -@enumx FruitU8::UInt8 Apple # no overflow even if first is typemin(T) +@enumx FruitU8::UInt8 Apple Banana # no overflow even if first is typemin(T) @test Base.Enums.basetype(FruitU8.T) === UInt8 @test FruitU8.Apple === FruitU8.T(0) +let io = IOBuffer() + show(io, "text/plain", FruitU8.T) + str = String(take!(io)) + @test str == "Enum type FruitU8.T <: Enum{UInt8} with 2 instances:\n FruitU8.Apple = 0x00\n FruitU8.Banana = 0x01" + show(io, "text/plain", FruitU8.Apple) + str = String(take!(io)) + @test str == "FruitU8.Apple = 0x00" + show(io, "text/plain", FruitU8.Banana) + str = String(take!(io)) + @test str == "FruitU8.Banana = 0x01" +end + @enumx Fruit16::T16 Apple @test Fruit16.T <: EnumX.Enum{Int16} <: Base.Enum{Int16} @test Base.Enums.basetype(Fruit16.T) === Int16