Skip to content

Commit

Permalink
test: add tests for C++ namespace support
Browse files Browse the repository at this point in the history
This combines some test input from Stephan Lachnit and myself.

Some of the results are likely not what's desired. Not everything
appears to get the namespace prefix, for example variables.

It's not clear that everything that appears to be missing a namespace
prefix should get a prefix either; for example class/struct/union
members, or enumerators, as they're nested within a parent that does
have the namespace prefix.

More than anything, the test documents the status quo, and provides a
way to make incremental improvements on top.
  • Loading branch information
jnikula committed Sep 4, 2024
1 parent 7396afe commit 9bdde44
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 0 deletions.
99 changes: 99 additions & 0 deletions test/cpp/namespace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace A {
namespace B {

/**
* Test fct A
*/
int testa(int a) { return a; }

/**
* Test cls B
*/
class TestB {
public:
/**
* Test fct B
*/
int testb(int b) { return b; }

private:
/** Not constant */
double b;
};


/** Some constant */
constexpr double CONSTANT = 5.;

} // namespace B

/**
* Test cls D
*/
class TestD : public B::TestB {
public:
/**
* Test fct D
*/
int testd() const { return d; }
private:
static double d;
};

/**
* Test fct C
*/
template<typename T>
int testc(int c) { return c; }

/**
* Test enum E
*/
enum class TestE {
/** enum member A */
A,
/** enum member B */
B,
};

} // namespace A


namespace foo {
/**
* foo_class
*/
class foo_class {
/** member */
int m;
};

/**
* foo_struct
*/
struct foo_struct {
/** member */
int m;
};

/**
* foo_union
*/
union foo_union {
/** member1 */
int m1;
/** member2 */
int m2;
};

/**
* Const.
*/
const int GLOBAL = 5;

/** enum */
enum foo_enum {
/** enumerator */
FOO_ENUMERATOR,
};
};
105 changes: 105 additions & 0 deletions test/cpp/namespace.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

.. cpp:function:: int A::B::testa(int a)

Test fct A


.. cpp:class:: A::B::TestB

Test cls B


.. cpp:function:: public int testb(int b)

Test fct B


.. cpp:member:: private double b

Not constant


.. cpp:var:: constexpr double CONSTANT

Some constant


.. cpp:class:: A::TestD: public A::B::TestB

Test cls D


.. cpp:function:: public int testd(void) const

Test fct D


.. cpp:function:: template<typename T> int A::testc(int c)

Test fct C


.. cpp:enum-class:: A::TestE

Test enum E


.. cpp:enumerator:: A

enum member A


.. cpp:enumerator:: B

enum member B


.. cpp:class:: foo::foo_class

foo_class


.. cpp:member:: private int m

member


.. cpp:struct:: foo::foo_struct

foo_struct


.. cpp:member:: public int m

member


.. cpp:union:: foo::foo_union

foo_union


.. cpp:member:: int m1

member1


.. cpp:member:: int m2

member2


.. cpp:var:: const int GLOBAL

Const.


.. cpp:enum:: foo::foo_enum

enum


.. cpp:enumerator:: FOO_ENUMERATOR

enumerator

6 changes: 6 additions & 0 deletions test/cpp/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
directives:
- domain: cpp
directive: autodoc
arguments:
- namespace.cpp
expected: namespace.rst

0 comments on commit 9bdde44

Please sign in to comment.