Make it possible to control the visibility of created enums.#16
Merged
Conversation
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/enum.jl b/src/enum.jl
index 4f3b93a..7470c1f 100644
--- a/src/enum.jl
+++ b/src/enum.jl
@@ -7,8 +7,8 @@ export @enum_without_prefix
# lack of namespacing in C, are to be used in Julia where we do have module namespacing.
macro enum_without_prefix(ex...)
# destructure keyword arguments
- call = ex[end-1:end]
- kwargs = map(ex[1:end-2]) do kwarg
+ call = ex[(end - 1):end]
+ kwargs = map(ex[1:(end - 2)]) do kwarg
if kwarg isa Symbol
:($kwarg = $kwarg)
elseif Meta.isexpr(kwarg, :(=))
@@ -45,7 +45,7 @@ macro enum_without_prefix(ex...)
for instance in instances(enum)
name = String(Symbol(instance))
@assert startswith(name, prefix)
- short = Symbol(name[length(prefix)+1:end])
+ short = Symbol(name[(length(prefix) + 1):end])
push!(ex.args, :(const $short = $(mod).$(Symbol(name))))
if visibility == :export
push!(ex.args, :(export $short))
diff --git a/test/runtests.jl b/test/runtests.jl
index fa2669b..9010233 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -89,9 +89,9 @@ using IOCapture
# test with visibility=:export
mod_export = @eval module $(gensym())
- using GPUToolbox
- @enum MY_ENUM MY_ENUM_A MY_ENUM_B
- @enum_without_prefix visibility=:export MY_ENUM MY_ENUM_
+ using GPUToolbox
+ @enum MY_ENUM MY_ENUM_A MY_ENUM_B
+ @enum_without_prefix visibility = :export MY_ENUM MY_ENUM_
end
@test mod_export.A == mod_export.MY_ENUM_A
@test mod_export.B == mod_export.MY_ENUM_B
@@ -102,9 +102,9 @@ using IOCapture
# test with visibility=:public
@static if VERSION >= v"1.11"
mod_public = @eval module $(gensym())
- using GPUToolbox
- @enum MY_ENUM MY_ENUM_P MY_ENUM_Q
- @enum_without_prefix visibility=:public MY_ENUM MY_ENUM_
+ using GPUToolbox
+ @enum MY_ENUM MY_ENUM_P MY_ENUM_Q
+ @enum_without_prefix visibility = :public MY_ENUM MY_ENUM_
end
@test mod_public.P == mod_public.MY_ENUM_P
@test mod_public.Q == mod_public.MY_ENUM_Q |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.