Skip to content

Commit af77cad

Browse files
committed
Add tests for C domain
1 parent d6b2dac commit af77cad

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c_maximum_signature_line_length = len("str hello(str name)") - 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
domain-c-c_maximum_signature_line_length
2+
========================================
3+
4+
.. c:function:: str hello(str name)

tests/test_domain_c.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
from xml.etree import ElementTree
66

77
import pytest
8+
from docutils import nodes
89

910
from sphinx import addnodes
10-
from sphinx.addnodes import desc
11+
from sphinx.addnodes import (desc, desc_name, desc_content, desc_parameter,
12+
desc_parameter_line, desc_parameterlist, desc_sig_name,
13+
desc_sig_space, desc_signature, desc_signature_line,
14+
pending_xref)
1115
from sphinx.domains.c import (DefinitionError, DefinitionParser, Symbol, _id_prefix,
1216
_macroKeywords, _max_id)
1317
from sphinx.ext.intersphinx import load_mappings, normalize_intersphinx_mapping
@@ -808,3 +812,68 @@ def test_domain_c_parse_noindexentry(app):
808812
assert_node(doctree, (addnodes.index, desc, addnodes.index, desc))
809813
assert_node(doctree[0], addnodes.index, entries=[('single', 'f (C function)', 'c.f', '', None)])
810814
assert_node(doctree[2], addnodes.index, entries=[])
815+
816+
817+
@pytest.mark.sphinx(
818+
'html',
819+
confoverrides={'c_maximum_signature_line_length': len("str hello(str name)")}
820+
)
821+
def test_cfunction_signature_with_c_maximum_signature_line_length(app):
822+
text = ".. c:function:: str hello(str name)"
823+
doctree = restructuredtext.parse(app, text)
824+
expected_doctree = (
825+
addnodes.index,
826+
[desc, ([desc_signature, ([desc_signature_line, (pending_xref,
827+
desc_sig_space,
828+
[desc_name, [desc_sig_name, "hello"]],
829+
desc_parameterlist)])],
830+
desc_content)]
831+
)
832+
assert_node(doctree, expected_doctree)
833+
assert_node(doctree[1], addnodes.desc, desctype="function",
834+
domain="c", objtype="function", noindex=False)
835+
signame_node = [desc_sig_name, "name"]
836+
expected_sig = [desc_parameterlist, desc_parameter, ([pending_xref, [desc_sig_name, "str"]],
837+
desc_sig_space,
838+
signame_node)]
839+
assert_node(doctree[1][0][0][3], expected_sig)
840+
841+
text = (".. c:function:: str hello(str names)\n"
842+
" :single-line-signature:")
843+
signame_node[1] = "names"
844+
doctree = restructuredtext.parse(app, text)
845+
assert_node(doctree, expected_doctree)
846+
assert_node(doctree[1], addnodes.desc, desctype="function",
847+
domain="c", objtype="function", noindex=False)
848+
assert_node(doctree[1][0][0][3], expected_sig)
849+
850+
text = ".. c:function:: str hello(str names)"
851+
doctree = restructuredtext.parse(app, text)
852+
expected_sig.insert(1, desc_parameter_line)
853+
assert_node(doctree, expected_doctree)
854+
assert_node(doctree[1], addnodes.desc, desctype="function",
855+
domain="c", objtype="function", noindex=False)
856+
assert_node(doctree[1][0][0][3], expected_sig)
857+
858+
859+
@pytest.mark.sphinx(
860+
'html', testroot='domain-c-c_maximum_signature_line_length',
861+
)
862+
def test_domain_c_c_maximum_signature_line_length(app, status, warning):
863+
app.build()
864+
content = (app.outdir / 'index.html').read_text(encoding='utf8')
865+
expected = '\n'.join((
866+
'<dl>',
867+
(
868+
'<dd><span class="n"><span class="pre">str</span></span><span class="w"> </span>'
869+
'<span class="n"><span class="pre">name</span></span>, </dd>'
870+
),
871+
'</dl>',
872+
'',
873+
(
874+
'<span class="sig-paren">)</span>'
875+
'<a class="headerlink" href="#c.hello" title="Permalink to this definition">¶</a>'
876+
'<br /></dt>'
877+
),
878+
))
879+
assert expected in content

0 commit comments

Comments
 (0)