Skip to content

Commit 261ef34

Browse files
committed
[TEST] example for enums in namespaces
1 parent 2596d61 commit 261ef34

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

tests/test_code_generator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def test_enums():
5858

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

61+
assert mod.Foo.MyEnum
62+
assert mod.Foo.MyEnum.B
63+
assert mod.Foo2.MyEnum
64+
assert mod.Foo2.MyEnum.D
65+
6166
foo = mod.Foo()
6267
my_enum = mod.Foo.MyEnum
6368
assert "Testing Enum documentation." in my_enum.__doc__

tests/test_files/enums.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@ class Foo
2020
case MyEnum::C : return 3;
2121
}
2222
};
23-
};
23+
};
24+
25+
namespace Foo2
26+
{
27+
28+
enum class MyEnum
29+
{
30+
A,C,D
31+
};
32+
};

tests/test_files/enums.pxd

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,47 @@
33
cdef extern from "enums.hpp":
44
cdef cppclass Foo:
55

6-
int enumToInt(MyEnum e)
6+
int enumToInt(Foo__MyEnum e)
7+
8+
cdef extern from "enums.hpp":
9+
cdef cppclass Foo2:
10+
pass
11+
712

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

10-
cpdef enum class MyEnum "Foo::MyEnum":
15+
cpdef enum Foo__MyEnum "Foo::MyEnum":
1116
# wrap-attach:
1217
# Foo
1318
#
19+
# wrap-as:
20+
# MyEnum
21+
#
1422
# wrap-doc:
1523
# Testing Enum documentation.
1624
A
1725
B
1826
C
1927

20-
cpdef enum class MyEnum2 "Foo::MyEnum2":
28+
cpdef enum MyEnum2 "Foo::MyEnum2":
2129
# wrap-attach:
2230
# Foo
2331
A
2432
B
25-
C
33+
C
34+
35+
cdef extern from "enums.hpp" namespace "Foo2":
36+
37+
cpdef enum Foo2__MyEnum "Foo2::MyEnum":
38+
# wrap-attach:
39+
# Foo2
40+
#
41+
# wrap-as:
42+
# MyEnum
43+
#
44+
# wrap-doc:
45+
# This is a second enum in another namespace.
46+
A
47+
C
48+
D
49+

0 commit comments

Comments
 (0)