From bcbff3fa8fde1b33d9e43446f9ce124cf972b033 Mon Sep 17 00:00:00 2001 From: Hannes Roest Date: Thu, 24 Mar 2022 14:10:18 -0400 Subject: [PATCH] [TEST] example for enums in namespaces --- tests/test_code_generator.py | 5 +++++ tests/test_files/enums.hpp | 11 ++++++++++- tests/test_files/enums.pxd | 32 ++++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/test_code_generator.py b/tests/test_code_generator.py index 97efceaa..5926a0b9 100644 --- a/tests/test_code_generator.py +++ b/tests/test_code_generator.py @@ -66,6 +66,11 @@ def test_enums(): 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__ diff --git a/tests/test_files/enums.hpp b/tests/test_files/enums.hpp index 569bcf3f..a15d3156 100644 --- a/tests/test_files/enums.hpp +++ b/tests/test_files/enums.hpp @@ -20,4 +20,13 @@ class Foo case MyEnum::C : return 3; } }; -}; \ No newline at end of file +}; + +namespace Foo2 +{ + + enum class MyEnum + { + A,C,D + }; +}; diff --git a/tests/test_files/enums.pxd b/tests/test_files/enums.pxd index d2006ff6..67cf4c19 100644 --- a/tests/test_files/enums.pxd +++ b/tests/test_files/enums.pxd @@ -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 \ No newline at end of file + 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 +