Skip to content

Commit

Permalink
[TEST] example for enums in namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hroest committed Mar 24, 2022
1 parent 2596d61 commit 261ef34
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/test_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def test_enums():

mod = autowrap.Utils.compile_and_import("enummodule", [target, ], include_dirs)

assert mod.Foo.MyEnum
assert mod.Foo.MyEnum.B
assert mod.Foo2.MyEnum
assert mod.Foo2.MyEnum.D

foo = mod.Foo()
my_enum = mod.Foo.MyEnum
assert "Testing Enum documentation." in my_enum.__doc__
Expand Down
11 changes: 10 additions & 1 deletion tests/test_files/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ class Foo
case MyEnum::C : return 3;
}
};
};
};

namespace Foo2
{

enum class MyEnum
{
A,C,D
};
};
32 changes: 28 additions & 4 deletions tests/test_files/enums.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,47 @@
cdef extern from "enums.hpp":
cdef cppclass Foo:

int enumToInt(MyEnum e)
int enumToInt(Foo__MyEnum e)

cdef extern from "enums.hpp":
cdef cppclass Foo2:
pass


cdef extern from "enums.hpp" namespace "Foo":

cpdef enum class MyEnum "Foo::MyEnum":
cpdef enum Foo__MyEnum "Foo::MyEnum":
# wrap-attach:
# Foo
#
# wrap-as:
# MyEnum
#
# wrap-doc:
# Testing Enum documentation.
A
B
C

cpdef enum class MyEnum2 "Foo::MyEnum2":
cpdef enum MyEnum2 "Foo::MyEnum2":
# wrap-attach:
# Foo
A
B
C
C

cdef extern from "enums.hpp" namespace "Foo2":

cpdef enum Foo2__MyEnum "Foo2::MyEnum":
# wrap-attach:
# Foo2
#
# wrap-as:
# MyEnum
#
# wrap-doc:
# This is a second enum in another namespace.
A
C
D

0 comments on commit 261ef34

Please sign in to comment.