Skip to content

Commit

Permalink
Fix show(...) of invalid instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 1, 2022
1 parent 4a8e89c commit 6120a51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "EnumX"
uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
version = "1.0.3"
version = "1.0.4"

[compat]
julia = "1.6"
Expand Down
5 changes: 5 additions & 0 deletions src/EnumX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

2 comments on commit 6120a51

@fredrikekre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/73246

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.4 -m "<description of version>" 6120a51ecd8bf90927479b564178e6b48d42e682
git push origin v1.0.4

Please sign in to comment.