mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Extract inner check functions in `test_domain_cpp
` (#12336)
This commit is contained in:
parent
172a2aa88e
commit
0d74c85e8c
@ -1046,19 +1046,21 @@ def test_domain_cpp_ast_attributes():
|
|||||||
check('enumerator', '{key}Foo [[attr1]] [[attr2]] = 42', {2: '3Foo'})
|
check('enumerator', '{key}Foo [[attr1]] [[attr2]] = 42', {2: '3Foo'})
|
||||||
|
|
||||||
|
|
||||||
def test_domain_cpp_ast_xref_parsing():
|
def check_ast_xref_parsing(target):
|
||||||
def check(target):
|
|
||||||
class Config:
|
class Config:
|
||||||
cpp_id_attributes = ["id_attr"]
|
cpp_id_attributes = ["id_attr"]
|
||||||
cpp_paren_attributes = ["paren_attr"]
|
cpp_paren_attributes = ["paren_attr"]
|
||||||
parser = DefinitionParser(target, location=None,
|
|
||||||
config=Config())
|
parser = DefinitionParser(target, location='', config=Config())
|
||||||
ast, isShorthand = parser.parse_xref_object()
|
parser.parse_xref_object()
|
||||||
parser.assert_end()
|
parser.assert_end()
|
||||||
check('f')
|
|
||||||
check('f()')
|
|
||||||
check('void f()')
|
def test_domain_cpp_ast_xref_parsing():
|
||||||
check('T f()')
|
check_ast_xref_parsing('f')
|
||||||
|
check_ast_xref_parsing('f()')
|
||||||
|
check_ast_xref_parsing('void f()')
|
||||||
|
check_ast_xref_parsing('T f()')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -1213,18 +1215,12 @@ def test_domain_cpp_build_misuse_of_roles(app, status, warning):
|
|||||||
def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, warning):
|
def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, warning):
|
||||||
app.build(force_all=True)
|
app.build(force_all=True)
|
||||||
|
|
||||||
def check(spec, text, file):
|
|
||||||
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
|
|
||||||
res = re.search(pattern, text)
|
|
||||||
if not res:
|
|
||||||
print(f"Pattern\n\t{pattern}\nnot found in {file}")
|
|
||||||
raise AssertionError
|
|
||||||
rolePatterns = [
|
rolePatterns = [
|
||||||
('', 'Sphinx'),
|
'Sphinx',
|
||||||
('', 'Sphinx::version'),
|
'Sphinx::version',
|
||||||
('', 'version'),
|
'version',
|
||||||
('', 'List'),
|
'List',
|
||||||
('', 'MyEnum'),
|
'MyEnum',
|
||||||
]
|
]
|
||||||
parenPatterns = [
|
parenPatterns = [
|
||||||
('ref function without parens ', r'paren_1\(\)'),
|
('ref function without parens ', r'paren_1\(\)'),
|
||||||
@ -1237,35 +1233,33 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app, status, war
|
|||||||
('ref op call with parens, explicit title ', 'paren_8_title'),
|
('ref op call with parens, explicit title ', 'paren_8_title'),
|
||||||
]
|
]
|
||||||
|
|
||||||
f = 'roles.html'
|
text = (app.outdir / 'roles.html').read_text(encoding='utf8')
|
||||||
t = (app.outdir / f).read_text(encoding='utf8')
|
for ref_text in rolePatterns:
|
||||||
for s in rolePatterns:
|
pattern = f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
|
||||||
check(s, t, f)
|
match = re.search(pattern, text)
|
||||||
for s in parenPatterns:
|
assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
|
||||||
check(s, t, f)
|
for (desc_text, ref_text) in parenPatterns:
|
||||||
|
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
|
||||||
|
match = re.search(pattern, text)
|
||||||
|
assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
|
||||||
|
|
||||||
f = 'any-role.html'
|
text = (app.outdir / 'any-role.html').read_text(encoding='utf8')
|
||||||
t = (app.outdir / f).read_text(encoding='utf8')
|
for (desc_text, ref_text) in parenPatterns:
|
||||||
for s in parenPatterns:
|
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
|
||||||
check(s, t, f)
|
match = re.search(pattern, text)
|
||||||
|
assert match is not None, f"Pattern not found in any-role.html:\n\t{pattern}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'add_function_parentheses': False})
|
@pytest.mark.sphinx(testroot='domain-cpp', confoverrides={'add_function_parentheses': False})
|
||||||
def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, warning):
|
def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, warning):
|
||||||
app.build(force_all=True)
|
app.build(force_all=True)
|
||||||
|
|
||||||
def check(spec, text, file):
|
|
||||||
pattern = '<li><p>%s<a .*?><code .*?><span .*?>%s</span></code></a></p></li>' % spec
|
|
||||||
res = re.search(pattern, text)
|
|
||||||
if not res:
|
|
||||||
print(f"Pattern\n\t{pattern}\nnot found in {file}")
|
|
||||||
raise AssertionError
|
|
||||||
rolePatterns = [
|
rolePatterns = [
|
||||||
('', 'Sphinx'),
|
'Sphinx',
|
||||||
('', 'Sphinx::version'),
|
'Sphinx::version',
|
||||||
('', 'version'),
|
'version',
|
||||||
('', 'List'),
|
'List',
|
||||||
('', 'MyEnum'),
|
'MyEnum',
|
||||||
]
|
]
|
||||||
parenPatterns = [
|
parenPatterns = [
|
||||||
('ref function without parens ', 'paren_1'),
|
('ref function without parens ', 'paren_1'),
|
||||||
@ -1278,17 +1272,21 @@ def test_domain_cpp_build_with_add_function_parentheses_is_False(app, status, wa
|
|||||||
('ref op call with parens, explicit title ', 'paren_8_title'),
|
('ref op call with parens, explicit title ', 'paren_8_title'),
|
||||||
]
|
]
|
||||||
|
|
||||||
f = 'roles.html'
|
text = (app.outdir / 'roles.html').read_text(encoding='utf8')
|
||||||
t = (app.outdir / f).read_text(encoding='utf8')
|
for ref_text in rolePatterns:
|
||||||
for s in rolePatterns:
|
pattern = f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
|
||||||
check(s, t, f)
|
match = re.search(pattern, text)
|
||||||
for s in parenPatterns:
|
assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
|
||||||
check(s, t, f)
|
for (desc_text, ref_text) in parenPatterns:
|
||||||
|
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
|
||||||
|
match = re.search(pattern, text)
|
||||||
|
assert match is not None, f"Pattern not found in roles.html:\n\t{pattern}"
|
||||||
|
|
||||||
f = 'any-role.html'
|
text = (app.outdir / 'any-role.html').read_text(encoding='utf8')
|
||||||
t = (app.outdir / f).read_text(encoding='utf8')
|
for (desc_text, ref_text) in parenPatterns:
|
||||||
for s in parenPatterns:
|
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
|
||||||
check(s, t, f)
|
match = re.search(pattern, text)
|
||||||
|
assert match is not None, f"Pattern not found in any-role.html:\n\t{pattern}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(testroot='domain-cpp')
|
@pytest.mark.sphinx(testroot='domain-cpp')
|
||||||
|
Loading…
Reference in New Issue
Block a user