diff --git a/cmake_modules/test_.hxx b/cmake_modules/test_.hxx index 1e2c1f7..80871a5 100644 --- a/cmake_modules/test_.hxx +++ b/cmake_modules/test_.hxx @@ -23,7 +23,7 @@ /// distinct test case using the same test body. In the scope of /// the test body, the parameter is declared as /// -/// .. cpp:var:: Parameter const ¶meter +/// .. var:: Parameter const ¶meter /// /// If parameters are read from an initializer list or other /// range then this is analogous to a @@ -82,7 +82,7 @@ /// // Expected: three == five /// // Actual: 3 vs 5 /// -/// :cpp:expr:`EXPECT_(...)` produces an expression rather than a statement. +/// :expr:`EXPECT_(...)` produces an expression rather than a statement. /// It is contextually convertible to ``bool``, truthy iff the condition /// was truthy. If additional context needs to be added to a failed /// expectation, a lambda can be provided which will only be called @@ -135,11 +135,11 @@ /// }; /// /// This may be omitted, in which case no state will be shared. -/// If it is provided it must precede all :cpp:expr:`TEST_(...)` +/// If it is provided it must precede all :expr:`TEST_(...)` /// definitions (this is checked at runtime). /// /// A pointer to the constructed state ``struct`` is accessible -/// in test bodies by calling :cpp:expr:`suite_state()`. +/// in test bodies by calling :expr:`suite_state()`. /// /// .. code-block:: /// diff --git a/cmake_modules/trike/test_trike.py b/cmake_modules/trike/test_trike.py index 62cc6b6..ce129cc 100644 --- a/cmake_modules/trike/test_trike.py +++ b/cmake_modules/trike/test_trike.py @@ -52,6 +52,12 @@ def test_basic(tmp_path): using cHAR = char; } // namespace baz + + /// e + enum Enum { + /// s + SCOPED + }; """, ) file_content = trike.comment_scan(path, clang_args=[]) @@ -126,6 +132,7 @@ def test_basic(tmp_path): clang_cursor_kind="TYPE_ALIAS_DECL", ), ), + 0 ] assert file_content.floating_comments == [ trike.Comment( diff --git a/cmake_modules/trike/trike/__init__.py b/cmake_modules/trike/trike/__init__.py index 41b5352..b3208dd 100644 --- a/cmake_modules/trike/trike/__init__.py +++ b/cmake_modules/trike/trike/__init__.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from contextlib import contextmanager from pathlib import Path import sphinx.util.logging @@ -427,6 +428,22 @@ class PutDirective(SphinxDirective): required_arguments = 2 optional_arguments = 1000 + @contextmanager + def default_cpp(self): + tmp = {} + tmp["highlight_language"] = self.env.temp_data.get("highlight_language", None) + self.env.temp_data["highlight_language"] = "cpp" + tmp["default_domain"] = self.env.temp_data.get("default_domain", None) + self.env.temp_data["default_domain"] = self.env.domains.get("cpp") + try: + yield + finally: + for key, value in tmp.items(): + if value is None: + del self.env.temp_data[key] + else: + self.env.temp_data[key] = value + def run(self) -> list[Node]: directive = self.arguments[0] namespace = self.env.temp_data.get("cpp:namespace_stack", [""])[-1] @@ -456,7 +473,8 @@ def run(self) -> list[Node]: *(f" {line}" for line in comment.stripped_text), ] ) - return self.parse_text_to_nodes(text) + with self.default_cpp(): + return self.parse_text_to_nodes(text) message = f"found no declaration matching `{declaration}`\n {context=}" for m in difflib.get_close_matches(declaration, declarations.keys()):