Skip to content

Commit

Permalink
Add tests for C++ domain
Browse files Browse the repository at this point in the history
  • Loading branch information
TLouf committed Jan 3, 2023
1 parent af77cad commit ea89180
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cpp_maximum_signature_line_length = len("str hello(str name)") - 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
domain-cpp-cpp_maximum_signature_line_length
============================================

.. cpp:function:: str hello(str name)
66 changes: 66 additions & 0 deletions tests/test_domain_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import zlib

import pytest
from docutils import nodes

import sphinx.domains.cpp as cppDomain
from sphinx import addnodes
from sphinx.addnodes import (desc, desc_name, desc_content, desc_parameter,
desc_parameter_line, desc_parameterlist, desc_sig_name,
desc_sig_space, desc_signature, desc_signature_line,
pending_xref)
from sphinx.addnodes import desc
from sphinx.domains.cpp import (DefinitionError, DefinitionParser, NoOldIdError, Symbol,
_id_prefix, _max_id)
Expand Down Expand Up @@ -1480,3 +1485,64 @@ def test_domain_cpp_normalize_unspecialized_template_args(make_app, app_params):
)
warning = app2._warning.getvalue()
assert 'Internal C++ domain error during symbol merging' not in warning


@pytest.mark.sphinx(
'html',
confoverrides={'cpp_maximum_signature_line_length': len("str hello(str name)")}
)
def test_cfunction_signature_with_c_maximum_signature_line_length(app):
text = ".. cpp:function:: str hello(str name)"
doctree = restructuredtext.parse(app, text)
expected_doctree = (
addnodes.index,
[desc, ([desc_signature, ([desc_signature_line, (pending_xref,
desc_sig_space,
[desc_name, [desc_sig_name, "hello"]],
desc_parameterlist)])],
desc_content)]
)
assert_node(doctree, expected_doctree)
assert_node(doctree[1], addnodes.desc, desctype="function",
domain="cpp", objtype="function", noindex=False)
signame_node = [desc_sig_name, "name"]
expected_sig = [desc_parameterlist, desc_parameter, ([pending_xref, [desc_sig_name, "str"]],
desc_sig_space,
signame_node)]
assert_node(doctree[1][0][0][3], expected_sig)

text = (".. cpp:function:: str hello(str names)\n"
" :single-line-signature:")
signame_node[1] = "names"
doctree = restructuredtext.parse(app, text)
assert_node(doctree, expected_doctree)
assert_node(doctree[1], addnodes.desc, desctype="function",
domain="cpp", objtype="function", noindex=False)
assert_node(doctree[1][0][0][3], expected_sig)

text = ".. cpp:function:: str hello(str names)"
doctree = restructuredtext.parse(app, text)
expected_sig.insert(1, desc_parameter_line)
assert_node(doctree, expected_doctree)
assert_node(doctree[1], addnodes.desc, desctype="function",
domain="cpp", objtype="function", noindex=False)
assert_node(doctree[1][0][0][3], expected_sig)


@pytest.mark.sphinx(
'html', testroot='domain-cpp-cpp_maximum_signature_line_length',
)
def test_domain_cpp_cpp_maximum_signature_line_length(app, status, warning):
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
expected = '\n'.join((
'<dl>',
(
'<dd><span class="n"><span class="pre">str</span></span><span class="w"> </span>'
'<span class="n sig-param"><span class="pre">name</span></span>, </dd>'
),
'</dl>',
'',
'<span class="sig-paren">)</span><a class="headerlink" href=',
))
assert expected in content

0 comments on commit ea89180

Please sign in to comment.