Browse Source

Add a test for empty enums.

pull/8/head
Fredrik Ekre 4 years ago
parent
commit
445a39ed6c
  1. 2
      src/EnumX.jl
  2. 14
      test/runtests.jl

2
src/EnumX.jl

@ -132,7 +132,7 @@ function Base.show(io::IO, ::MIME"text/plain", ::Base.Type{E}) where E <: Enum @@ -132,7 +132,7 @@ function Base.show(io::IO, ::MIME"text/plain", ::Base.Type{E}) where E <: Enum
mx = maximum(x -> textwidth(x.first), stringmap; init = 0)
print(iob,
"Enum type $(nameof(parentmodule(E))).$(nameof(E)) <: ",
"Enum{$(Base.Enums.basetype(E))} with $(n) instance$(n == 1 ? "" : "s"):"
"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)")

14
test/runtests.jl

@ -213,7 +213,6 @@ end @@ -213,7 +213,6 @@ end
@test FruitT.Apple === FruitT.Typ(0)
let io = IOBuffer()
io = IOBuffer()
show(io, "text/plain", FruitT.Typ)
str = String(take!(io))
@test str == "Enum type FruitT.Typ <: Enum{Int32} with 2 instances:\n FruitT.Apple = 0\n FruitT.Banana = 1"
@ -235,4 +234,17 @@ catch err @@ -235,4 +234,17 @@ catch err
@test err.msg == "instance name Fruit.Apple reserved for the Enum typename."
end
# Empty enum
@enumx FruitEmpty
@test instances(FruitEmpty.T) == ()
let io = IOBuffer()
show(io, "text/plain", FruitEmpty.T)
str = String(take!(io))
@test str == "Enum type FruitEmpty.T <: Enum{Int32} with 0 instances"
end
@enumx T=Typ FruitEmptyT
@test instances(FruitEmptyT.Typ) == ()
end # testset

Loading…
Cancel
Save