-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix C/C++ domain support for :node-id: and :symbol-ids:
Previously, these were not properly taken into account by parameter objects.
- Loading branch information
Showing
9 changed files
with
237 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"""Tests C++ domain functionality added by this theme.""" | ||
|
||
import json | ||
|
||
import docutils.nodes | ||
import pytest | ||
|
||
pytest_plugins = ("sphinx.testing.fixtures",) | ||
|
||
|
||
def snapshot_references(app, snapshot): | ||
doc = app.env.get_and_resolve_doctree("index", app.builder) | ||
|
||
nodes = list(doc.findall(condition=docutils.nodes.reference)) | ||
|
||
node_data = [ | ||
{ | ||
"text": node.astext(), | ||
**{ | ||
attr: node.get(attr) | ||
for attr in ["refid", "refurl", "reftitle"] | ||
if attr in node | ||
}, | ||
} | ||
for node in nodes | ||
] | ||
|
||
snapshot.assert_match("\n".join(json.dumps(n) for n in node_data), "references.txt") | ||
|
||
|
||
@pytest.mark.parametrize("node_id", [None, "", "abc"]) | ||
def test_parameter_objects(immaterial_make_app, snapshot, node_id: str): | ||
"""Tests that parameter objects take into account the `node-id` option.""" | ||
|
||
attrs = [] | ||
if node_id is not None: | ||
attrs.append(f":node-id: {node_id}") | ||
attrs_text = "\n".join(attrs) | ||
|
||
app = immaterial_make_app( | ||
files={ | ||
"index.rst": f""" | ||
.. cpp:function:: void foo(int bar, int baz, int undocumented); | ||
{attrs_text} | ||
Test function. | ||
:param bar: Bar parameter. | ||
:param baz: Baz parameter. | ||
""", | ||
}, | ||
) | ||
|
||
app.build() | ||
|
||
snapshot_references(app, snapshot) | ||
|
||
|
||
def test_template_parameter_objects(immaterial_make_app, snapshot): | ||
"""Tests that xrefs to template parameters include template parameter kind | ||
in tooltip text.""" | ||
app = immaterial_make_app( | ||
files={ | ||
"index.rst": """ | ||
.. cpp:function:: template <typename T, int N, template<typename> class U>\ | ||
void foo(); | ||
Test function. | ||
:tparam T: T parameter. | ||
:tparam N: N parameter. | ||
""", | ||
}, | ||
) | ||
|
||
app.build() | ||
|
||
snapshot_references(app, snapshot) | ||
|
||
|
||
def test_macro_parameter_objects(immaterial_make_app, snapshot): | ||
"""Tests that macro parameters work correctly.""" | ||
app = immaterial_make_app( | ||
files={ | ||
"index.rst": """ | ||
.. c:macro:: FOO(a, b, c) | ||
Test macro. | ||
:param a: A parameter. | ||
:param b: B parameter. | ||
""", | ||
}, | ||
) | ||
|
||
app.build() | ||
|
||
snapshot_references(app, snapshot) |
3 changes: 3 additions & 0 deletions
3
tests/snapshots/cpp_domain_test/test_macro_parameter_objects/references.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"text": "a", "refid": "c.FOO-p-a", "reftitle": "a (C macro parameter) \u2014 A parameter."} | ||
{"text": "b", "refid": "c.FOO-p-b", "reftitle": "b (C macro parameter) \u2014 B parameter."} | ||
{"text": "c", "refid": "c.FOO", "reftitle": "c (C macro parameter)"} |
3 changes: 3 additions & 0 deletions
3
tests/snapshots/cpp_domain_test/test_parameter_objects/None/references.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"text": "bar", "refid": "_CPPv43fooiii-p-bar", "reftitle": "foo::bar (C++ function parameter) \u2014 Bar parameter."} | ||
{"text": "baz", "refid": "_CPPv43fooiii-p-baz", "reftitle": "foo::baz (C++ function parameter) \u2014 Baz parameter."} | ||
{"text": "undocumented", "refid": "_CPPv43fooiii", "reftitle": "foo::undocumented (C++ function parameter)"} |
3 changes: 3 additions & 0 deletions
3
tests/snapshots/cpp_domain_test/test_parameter_objects/abc/references.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"text": "bar", "refid": "abc-p-bar", "reftitle": "foo::bar (C++ function parameter) \u2014 Bar parameter."} | ||
{"text": "baz", "refid": "abc-p-baz", "reftitle": "foo::baz (C++ function parameter) \u2014 Baz parameter."} | ||
{"text": "undocumented", "refid": "abc", "reftitle": "foo::undocumented (C++ function parameter)"} |
3 changes: 3 additions & 0 deletions
3
tests/snapshots/cpp_domain_test/test_parameter_objects/empty/references.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"text": "bar", "refid": "p-bar", "reftitle": "foo::bar (C++ function parameter) \u2014 Bar parameter."} | ||
{"text": "baz", "refid": "p-baz", "reftitle": "foo::baz (C++ function parameter) \u2014 Baz parameter."} | ||
{"text": "undocumented", "refid": "", "reftitle": "foo::undocumented (C++ function parameter)"} |
3 changes: 3 additions & 0 deletions
3
tests/snapshots/cpp_domain_test/test_template_parameter_objects/references.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"text": "T", "refid": "_CPPv4I0_iI0E0E3foovv-p-T", "reftitle": "foo::T (C++ type template parameter) \u2014 T parameter."} | ||
{"text": "N", "refid": "_CPPv4I0_iI0E0E3foovv-p-N", "reftitle": "foo::N (C++ non-type template parameter) \u2014 N parameter."} | ||
{"text": "U", "refid": "_CPPv4I0_iI0E0E3foovv", "reftitle": "foo::U (C++ template template parameter)"} |