|
5 | 5 | import zlib |
6 | 6 |
|
7 | 7 | import pytest |
| 8 | +from docutils import nodes |
8 | 9 |
|
9 | 10 | import sphinx.domains.cpp as cppDomain |
10 | 11 | from sphinx import addnodes |
| 12 | +from sphinx.addnodes import (desc, desc_name, desc_content, desc_parameter, |
| 13 | + desc_parameter_line, desc_parameterlist, desc_sig_name, |
| 14 | + desc_sig_space, desc_signature, desc_signature_line, |
| 15 | + pending_xref) |
11 | 16 | from sphinx.addnodes import desc |
12 | 17 | from sphinx.domains.cpp import (DefinitionError, DefinitionParser, NoOldIdError, Symbol, |
13 | 18 | _id_prefix, _max_id) |
@@ -1480,3 +1485,64 @@ def test_domain_cpp_normalize_unspecialized_template_args(make_app, app_params): |
1480 | 1485 | ) |
1481 | 1486 | warning = app2._warning.getvalue() |
1482 | 1487 | assert 'Internal C++ domain error during symbol merging' not in warning |
| 1488 | + |
| 1489 | + |
| 1490 | +@pytest.mark.sphinx( |
| 1491 | + 'html', |
| 1492 | + confoverrides={'cpp_maximum_signature_line_length': len("str hello(str name)")} |
| 1493 | +) |
| 1494 | +def test_cfunction_signature_with_c_maximum_signature_line_length(app): |
| 1495 | + text = ".. cpp:function:: str hello(str name)" |
| 1496 | + doctree = restructuredtext.parse(app, text) |
| 1497 | + expected_doctree = ( |
| 1498 | + addnodes.index, |
| 1499 | + [desc, ([desc_signature, ([desc_signature_line, (pending_xref, |
| 1500 | + desc_sig_space, |
| 1501 | + [desc_name, [desc_sig_name, "hello"]], |
| 1502 | + desc_parameterlist)])], |
| 1503 | + desc_content)] |
| 1504 | + ) |
| 1505 | + assert_node(doctree, expected_doctree) |
| 1506 | + assert_node(doctree[1], addnodes.desc, desctype="function", |
| 1507 | + domain="cpp", objtype="function", noindex=False) |
| 1508 | + signame_node = [desc_sig_name, "name"] |
| 1509 | + expected_sig = [desc_parameterlist, desc_parameter, ([pending_xref, [desc_sig_name, "str"]], |
| 1510 | + desc_sig_space, |
| 1511 | + signame_node)] |
| 1512 | + assert_node(doctree[1][0][0][3], expected_sig) |
| 1513 | + |
| 1514 | + text = (".. cpp:function:: str hello(str names)\n" |
| 1515 | + " :single-line-signature:") |
| 1516 | + signame_node[1] = "names" |
| 1517 | + doctree = restructuredtext.parse(app, text) |
| 1518 | + assert_node(doctree, expected_doctree) |
| 1519 | + assert_node(doctree[1], addnodes.desc, desctype="function", |
| 1520 | + domain="cpp", objtype="function", noindex=False) |
| 1521 | + assert_node(doctree[1][0][0][3], expected_sig) |
| 1522 | + |
| 1523 | + text = ".. cpp:function:: str hello(str names)" |
| 1524 | + doctree = restructuredtext.parse(app, text) |
| 1525 | + expected_sig.insert(1, desc_parameter_line) |
| 1526 | + assert_node(doctree, expected_doctree) |
| 1527 | + assert_node(doctree[1], addnodes.desc, desctype="function", |
| 1528 | + domain="cpp", objtype="function", noindex=False) |
| 1529 | + assert_node(doctree[1][0][0][3], expected_sig) |
| 1530 | + |
| 1531 | + |
| 1532 | +@pytest.mark.sphinx( |
| 1533 | + 'html', testroot='domain-cpp-cpp_maximum_signature_line_length', |
| 1534 | +) |
| 1535 | +def test_domain_cpp_cpp_maximum_signature_line_length(app, status, warning): |
| 1536 | + app.build() |
| 1537 | + content = (app.outdir / 'index.html').read_text(encoding='utf8') |
| 1538 | + expected = '\n'.join(( |
| 1539 | + '<dl>', |
| 1540 | + ( |
| 1541 | + '<dd><span class="n"><span class="pre">str</span></span><span class="w"> </span>' |
| 1542 | + '<span class="n sig-param"><span class="pre">name</span></span>, </dd>' |
| 1543 | + ), |
| 1544 | + '</dl>', |
| 1545 | + '', |
| 1546 | + '<span class="sig-paren">)</span><a class="headerlink" href=', |
| 1547 | + )) |
| 1548 | + assert expected in content |
0 commit comments