Avoid using camelCase names in domain tests

This commit is contained in:
Adam Turner 2024-12-09 15:10:18 +00:00
parent 51bbfe259e
commit ce070af2fa
3 changed files with 383 additions and 383 deletions

View File

@ -49,62 +49,62 @@ def parse(name, string):
return ast return ast
def _check(name, input, idDict, output, key, asTextOutput): def _check(name, input, id_dict, output, key, as_text_output):
if key is None: if key is None:
key = name key = name
key += ' ' key += ' '
if name in {'function', 'member'}: if name in {'function', 'member'}:
inputActual = input input_actual = input
outputAst = output output_ast = output
outputAsText = output output_as_text = output
else: else:
inputActual = input.format(key='') input_actual = input.format(key='')
outputAst = output.format(key='') output_ast = output.format(key='')
outputAsText = output.format(key=key) output_as_text = output.format(key=key)
if asTextOutput is not None: if as_text_output is not None:
outputAsText = asTextOutput output_as_text = as_text_output
# first a simple check of the AST # first a simple check of the AST
ast = parse(name, inputActual) ast = parse(name, input_actual)
res = str(ast) res = str(ast)
if res != outputAst: if res != output_ast:
print() print()
print('Input: ', input) print('Input: ', input)
print('Result: ', res) print('Result: ', res)
print('Expected: ', outputAst) print('Expected: ', output_ast)
raise DefinitionError raise DefinitionError
rootSymbol = Symbol(None, None, None, None, None) root_symbol = Symbol(None, None, None, None, None)
symbol = rootSymbol.add_declaration(ast, docname='TestDoc', line=42) symbol = root_symbol.add_declaration(ast, docname='TestDoc', line=42)
parentNode = addnodes.desc() parent_node = addnodes.desc()
signode = addnodes.desc_signature(input, '') signode = addnodes.desc_signature(input, '')
parentNode += signode parent_node += signode
ast.describe_signature(signode, 'lastIsName', symbol, options={}) ast.describe_signature(signode, 'lastIsName', symbol, options={})
resAsText = parentNode.astext() res_as_text = parent_node.astext()
if resAsText != outputAsText: if res_as_text != output_as_text:
print() print()
print('Input: ', input) print('Input: ', input)
print('astext(): ', resAsText) print('astext(): ', res_as_text)
print('Expected: ', outputAsText) print('Expected: ', output_as_text)
raise DefinitionError raise DefinitionError
idExpected = [None] id_expected = [None]
for i in range(1, _max_id + 1): for i in range(1, _max_id + 1):
if i in idDict: if i in id_dict:
idExpected.append(idDict[i]) id_expected.append(id_dict[i])
else: else:
idExpected.append(idExpected[i - 1]) id_expected.append(id_expected[i - 1])
idActual = [None] id_actual = [None]
for i in range(1, _max_id + 1): for i in range(1, _max_id + 1):
# try: # try:
id = ast.get_id(version=i) id = ast.get_id(version=i)
assert id is not None assert id is not None
idActual.append(id[len(_id_prefix[i]) :]) id_actual.append(id[len(_id_prefix[i]) :])
# except NoOldIdError: # except NoOldIdError:
# idActual.append(None) # id_actual.append(None)
res = [True] res = [True]
for i in range(1, _max_id + 1): for i in range(1, _max_id + 1):
res.append(idExpected[i] == idActual[i]) res.append(id_expected[i] == id_actual[i])
if not all(res): if not all(res):
print('input: %s' % input.rjust(20)) print('input: %s' % input.rjust(20))
@ -112,31 +112,31 @@ def _check(name, input, idDict, output, key, asTextOutput):
if res[i]: if res[i]:
continue continue
print('Error in id version %d.' % i) print('Error in id version %d.' % i)
print('result: %s' % idActual[i]) print('result: %s' % id_actual[i])
print('expected: %s' % idExpected[i]) print('expected: %s' % id_expected[i])
# print(rootSymbol.dump(0)) # print(root_symbol.dump(0))
raise DefinitionError raise DefinitionError
def check(name, input, idDict, output=None, key=None, asTextOutput=None): def check(name, input, id_dict, output=None, key=None, as_text_output=None):
if output is None: if output is None:
output = input output = input
# First, check without semicolon # First, check without semicolon
_check(name, input, idDict, output, key, asTextOutput) _check(name, input, id_dict, output, key, as_text_output)
if name != 'macro': if name != 'macro':
# Second, check with semicolon # Second, check with semicolon
_check( _check(
name, name,
input + ' ;', input + ' ;',
idDict, id_dict,
output + ';', output + ';',
key, key,
asTextOutput + ';' if asTextOutput is not None else None, as_text_output + ';' if as_text_output is not None else None,
) )
def test_domain_c_ast_expressions(): def test_domain_c_ast_expressions():
def exprCheck(expr, output=None): def expr_check(expr, output=None):
parser = DefinitionParser(expr, location=None, config=Config()) parser = DefinitionParser(expr, location=None, config=Config())
parser.allowFallbackExpressionParsing = False parser.allowFallbackExpressionParsing = False
ast = parser.parse_expression() ast = parser.parse_expression()
@ -151,30 +151,30 @@ def test_domain_c_ast_expressions():
print('Result: ', res) print('Result: ', res)
print('Expected: ', output) print('Expected: ', output)
raise DefinitionError raise DefinitionError
displayString = ast.get_display_string() display_string = ast.get_display_string()
if res != displayString: if res != display_string:
# note: if the expression contains an anon name then this will trigger a falsely # note: if the expression contains an anon name then this will trigger a falsely
print() print()
print('Input: ', expr) print('Input: ', expr)
print('Result: ', res) print('Result: ', res)
print('Display: ', displayString) print('Display: ', display_string)
raise DefinitionError raise DefinitionError
# type expressions # type expressions
exprCheck('int*') expr_check('int*')
exprCheck('int *const*') expr_check('int *const*')
exprCheck('int *volatile*') expr_check('int *volatile*')
exprCheck('int *restrict*') expr_check('int *restrict*')
exprCheck('int *(*)(double)') expr_check('int *(*)(double)')
exprCheck('const int*') expr_check('const int*')
exprCheck('__int64') expr_check('__int64')
exprCheck('unsigned __int64') expr_check('unsigned __int64')
# actual expressions # actual expressions
# primary # primary
exprCheck('true') expr_check('true')
exprCheck('false') expr_check('false')
ints = [ ints = [
'5', '5',
'0', '0',
@ -188,15 +188,15 @@ def test_domain_c_ast_expressions():
"0x0'1'2", "0x0'1'2",
"1'2'3", "1'2'3",
] ]
unsignedSuffix = ['', 'u', 'U'] unsigned_suffix = ['', 'u', 'U']
longSuffix = ['', 'l', 'L', 'll', 'LL'] long_suffix = ['', 'l', 'L', 'll', 'LL']
for i in ints: for i in ints:
for u in unsignedSuffix: for u in unsigned_suffix:
for l in longSuffix: for l in long_suffix:
expr = i + u + l expr = i + u + l
exprCheck(expr) expr_check(expr)
expr = i + l + u expr = i + l + u
exprCheck(expr) expr_check(expr)
for suffix in ('', 'f', 'F', 'l', 'L'): for suffix in ('', 'f', 'F', 'l', 'L'):
for e in ( for e in (
'5e42', '5e42',
@ -220,7 +220,7 @@ def test_domain_c_ast_expressions():
"1'2'3.4'5'6e7'8'9", "1'2'3.4'5'6e7'8'9",
): ):
expr = e + suffix expr = e + suffix
exprCheck(expr) expr_check(expr)
for e in ( for e in (
'ApF', 'ApF',
'Ap+F', 'Ap+F',
@ -243,94 +243,94 @@ def test_domain_c_ast_expressions():
"A'B'C.D'E'Fp1'2'3", "A'B'C.D'E'Fp1'2'3",
): ):
expr = '0x' + e + suffix expr = '0x' + e + suffix
exprCheck(expr) expr_check(expr)
exprCheck('"abc\\"cba"') # string expr_check('"abc\\"cba"') # string
# character literals # character literals
for p in ('', 'u8', 'u', 'U', 'L'): for p in ('', 'u8', 'u', 'U', 'L'):
exprCheck(p + "'a'") expr_check(p + "'a'")
exprCheck(p + "'\\n'") expr_check(p + "'\\n'")
exprCheck(p + "'\\012'") expr_check(p + "'\\012'")
exprCheck(p + "'\\0'") expr_check(p + "'\\0'")
exprCheck(p + "'\\x0a'") expr_check(p + "'\\x0a'")
exprCheck(p + "'\\x0A'") expr_check(p + "'\\x0A'")
exprCheck(p + "'\\u0a42'") expr_check(p + "'\\u0a42'")
exprCheck(p + "'\\u0A42'") expr_check(p + "'\\u0A42'")
exprCheck(p + "'\\U0001f34c'") expr_check(p + "'\\U0001f34c'")
exprCheck(p + "'\\U0001F34C'") expr_check(p + "'\\U0001F34C'")
exprCheck('(5)') expr_check('(5)')
exprCheck('C') expr_check('C')
# postfix # postfix
exprCheck('A(2)') expr_check('A(2)')
exprCheck('A[2]') expr_check('A[2]')
exprCheck('a.b.c') expr_check('a.b.c')
exprCheck('a->b->c') expr_check('a->b->c')
exprCheck('i++') expr_check('i++')
exprCheck('i--') expr_check('i--')
# unary # unary
exprCheck('++5') expr_check('++5')
exprCheck('--5') expr_check('--5')
exprCheck('*5') expr_check('*5')
exprCheck('&5') expr_check('&5')
exprCheck('+5') expr_check('+5')
exprCheck('-5') expr_check('-5')
exprCheck('!5') expr_check('!5')
exprCheck('not 5') expr_check('not 5')
exprCheck('~5') expr_check('~5')
exprCheck('compl 5') expr_check('compl 5')
exprCheck('sizeof(T)') expr_check('sizeof(T)')
exprCheck('sizeof -42') expr_check('sizeof -42')
exprCheck('alignof(T)') expr_check('alignof(T)')
# cast # cast
exprCheck('(int)2') expr_check('(int)2')
# binary op # binary op
exprCheck('5 || 42') expr_check('5 || 42')
exprCheck('5 or 42') expr_check('5 or 42')
exprCheck('5 && 42') expr_check('5 && 42')
exprCheck('5 and 42') expr_check('5 and 42')
exprCheck('5 | 42') expr_check('5 | 42')
exprCheck('5 bitor 42') expr_check('5 bitor 42')
exprCheck('5 ^ 42') expr_check('5 ^ 42')
exprCheck('5 xor 42') expr_check('5 xor 42')
exprCheck('5 & 42') expr_check('5 & 42')
exprCheck('5 bitand 42') expr_check('5 bitand 42')
# ['==', '!='] # ['==', '!=']
exprCheck('5 == 42') expr_check('5 == 42')
exprCheck('5 != 42') expr_check('5 != 42')
exprCheck('5 not_eq 42') expr_check('5 not_eq 42')
# ['<=', '>=', '<', '>'] # ['<=', '>=', '<', '>']
exprCheck('5 <= 42') expr_check('5 <= 42')
exprCheck('5 >= 42') expr_check('5 >= 42')
exprCheck('5 < 42') expr_check('5 < 42')
exprCheck('5 > 42') expr_check('5 > 42')
# ['<<', '>>'] # ['<<', '>>']
exprCheck('5 << 42') expr_check('5 << 42')
exprCheck('5 >> 42') expr_check('5 >> 42')
# ['+', '-'] # ['+', '-']
exprCheck('5 + 42') expr_check('5 + 42')
exprCheck('5 - 42') expr_check('5 - 42')
# ['*', '/', '%'] # ['*', '/', '%']
exprCheck('5 * 42') expr_check('5 * 42')
exprCheck('5 / 42') expr_check('5 / 42')
exprCheck('5 % 42') expr_check('5 % 42')
# ['.*', '->*'] # ['.*', '->*']
# conditional # conditional
# TODO # TODO
# assignment # assignment
exprCheck('a = 5') expr_check('a = 5')
exprCheck('a *= 5') expr_check('a *= 5')
exprCheck('a /= 5') expr_check('a /= 5')
exprCheck('a %= 5') expr_check('a %= 5')
exprCheck('a += 5') expr_check('a += 5')
exprCheck('a -= 5') expr_check('a -= 5')
exprCheck('a >>= 5') expr_check('a >>= 5')
exprCheck('a <<= 5') expr_check('a <<= 5')
exprCheck('a &= 5') expr_check('a &= 5')
exprCheck('a and_eq 5') expr_check('a and_eq 5')
exprCheck('a ^= 5') expr_check('a ^= 5')
exprCheck('a xor_eq 5') expr_check('a xor_eq 5')
exprCheck('a |= 5') expr_check('a |= 5')
exprCheck('a or_eq 5') expr_check('a or_eq 5')
def test_domain_c_ast_fundamental_types(): def test_domain_c_ast_fundamental_types():
@ -588,29 +588,29 @@ def test_domain_c_ast_enum_definitions():
def test_domain_c_ast_anon_definitions(): def test_domain_c_ast_anon_definitions():
check('struct', '@a', {1: '@a'}, asTextOutput='struct [anonymous]') check('struct', '@a', {1: '@a'}, as_text_output='struct [anonymous]')
check('union', '@a', {1: '@a'}, asTextOutput='union [anonymous]') check('union', '@a', {1: '@a'}, as_text_output='union [anonymous]')
check('enum', '@a', {1: '@a'}, asTextOutput='enum [anonymous]') check('enum', '@a', {1: '@a'}, as_text_output='enum [anonymous]')
check('struct', '@1', {1: '@1'}, asTextOutput='struct [anonymous]') check('struct', '@1', {1: '@1'}, as_text_output='struct [anonymous]')
check('struct', '@a.A', {1: '@a.A'}, asTextOutput='struct [anonymous].A') check('struct', '@a.A', {1: '@a.A'}, as_text_output='struct [anonymous].A')
def test_domain_c_ast_initializers(): def test_domain_c_ast_initializers():
idsMember = {1: 'v'} ids_member = {1: 'v'}
idsFunction = {1: 'f'} ids_function = {1: 'f'}
# no init # no init
check('member', 'T v', idsMember) check('member', 'T v', ids_member)
check('function', 'void f(T v)', idsFunction) check('function', 'void f(T v)', ids_function)
# with '=', assignment-expression # with '=', assignment-expression
check('member', 'T v = 42', idsMember) check('member', 'T v = 42', ids_member)
check('function', 'void f(T v = 42)', idsFunction) check('function', 'void f(T v = 42)', ids_function)
# with '=', braced-init # with '=', braced-init
check('member', 'T v = {}', idsMember) check('member', 'T v = {}', ids_member)
check('function', 'void f(T v = {})', idsFunction) check('function', 'void f(T v = {})', ids_function)
check('member', 'T v = {42, 42, 42}', idsMember) check('member', 'T v = {42, 42, 42}', ids_member)
check('function', 'void f(T v = {42, 42, 42})', idsFunction) check('function', 'void f(T v = {42, 42, 42})', ids_function)
check('member', 'T v = {42, 42, 42,}', idsMember) check('member', 'T v = {42, 42, 42,}', ids_member)
check('function', 'void f(T v = {42, 42, 42,})', idsFunction) check('function', 'void f(T v = {42, 42, 42,})', ids_function)
# TODO: designator-list # TODO: designator-list
@ -723,9 +723,9 @@ def extract_role_links(app, filename):
entries = [] entries = []
for l in lis: for l in lis:
li = ET.fromstring(l) # NoQA: S314 # using known data in tests li = ET.fromstring(l) # NoQA: S314 # using known data in tests
aList = list(li.iter('a')) a_list = list(li.iter('a'))
assert len(aList) == 1 assert len(a_list) == 1
a = aList[0] a = a_list[0]
target = a.attrib['href'].lstrip('#') target = a.attrib['href'].lstrip('#')
title = a.attrib['title'] title = a.attrib['title']
assert len(a) == 1 assert len(a) == 1
@ -808,12 +808,12 @@ def test_domain_c_build_field_role(app):
assert len(ws) == 0 assert len(ws) == 0
def _get_obj(app, queryName): def _get_obj(app, query_name):
domain = app.env.domains.c_domain domain = app.env.domains.c_domain
for name, _dispname, objectType, docname, anchor, _prio in domain.get_objects(): for name, _dispname, object_type, docname, anchor, _prio in domain.get_objects():
if name == queryName: if name == query_name:
return docname, anchor, objectType return docname, anchor, object_type
return queryName, 'not', 'found' return query_name, 'not', 'found'
@pytest.mark.sphinx( @pytest.mark.sphinx(
@ -822,7 +822,7 @@ def _get_obj(app, queryName):
def test_domain_c_build_intersphinx(tmp_path, app): def test_domain_c_build_intersphinx(tmp_path, app):
# a splitting of test_ids_vs_tags0 into the primary directives in a remote project, # a splitting of test_ids_vs_tags0 into the primary directives in a remote project,
# and then the references in the test project # and then the references in the test project
origSource = """\ orig_source = """\
.. c:member:: int _member .. c:member:: int _member
.. c:var:: int _var .. c:var:: int _var
.. c:function:: void _function() .. c:function:: void _function()

View File

@ -51,63 +51,63 @@ def parse(name, string):
return ast return ast
def _check(name, input, idDict, output, key, asTextOutput): def _check(name, input, id_dict, output, key, as_text_output):
if key is None: if key is None:
key = name key = name
key += ' ' key += ' '
if name in {'function', 'member'}: if name in {'function', 'member'}:
inputActual = input input_actual = input
outputAst = output output_ast = output
outputAsText = output output_as_text = output
else: else:
inputActual = input.format(key='') input_actual = input.format(key='')
outputAst = output.format(key='') output_ast = output.format(key='')
outputAsText = output.format(key=key) output_as_text = output.format(key=key)
if asTextOutput is not None: if as_text_output is not None:
outputAsText = asTextOutput output_as_text = as_text_output
# first a simple check of the AST # first a simple check of the AST
ast = parse(name, inputActual) ast = parse(name, input_actual)
res = str(ast) res = str(ast)
if res != outputAst: if res != output_ast:
print() print()
print('Input: ', input) print('Input: ', input)
print('Result: ', res) print('Result: ', res)
print('Expected: ', outputAst) print('Expected: ', output_ast)
raise DefinitionError raise DefinitionError
rootSymbol = Symbol(None, None, None, None, None, None, None) root_symbol = Symbol(None, None, None, None, None, None, None)
symbol = rootSymbol.add_declaration(ast, docname='TestDoc', line=42) symbol = root_symbol.add_declaration(ast, docname='TestDoc', line=42)
parentNode = addnodes.desc() parent_node = addnodes.desc()
signode = addnodes.desc_signature(input, '') signode = addnodes.desc_signature(input, '')
parentNode += signode parent_node += signode
ast.describe_signature(signode, 'lastIsName', symbol, options={}) ast.describe_signature(signode, 'lastIsName', symbol, options={})
resAsText = parentNode.astext() res_as_text = parent_node.astext()
if resAsText != outputAsText: if res_as_text != output_as_text:
print() print()
print('Input: ', input) print('Input: ', input)
print('astext(): ', resAsText) print('astext(): ', res_as_text)
print('Expected: ', outputAsText) print('Expected: ', output_as_text)
print('Node:', parentNode) print('Node:', parent_node)
raise DefinitionError raise DefinitionError
idExpected = [None] id_expected = [None]
for i in range(1, _max_id + 1): for i in range(1, _max_id + 1):
if i in idDict: if i in id_dict:
idExpected.append(idDict[i]) id_expected.append(id_dict[i])
else: else:
idExpected.append(idExpected[i - 1]) id_expected.append(id_expected[i - 1])
idActual = [None] id_actual = [None]
for i in range(1, _max_id + 1): for i in range(1, _max_id + 1):
try: try:
id = ast.get_id(version=i) id = ast.get_id(version=i)
assert id is not None assert id is not None
idActual.append(id[len(_id_prefix[i]) :]) id_actual.append(id[len(_id_prefix[i]) :])
except NoOldIdError: except NoOldIdError:
idActual.append(None) id_actual.append(None)
res = [True] res = [True]
for i in range(1, _max_id + 1): for i in range(1, _max_id + 1):
res.append(idExpected[i] == idActual[i]) res.append(id_expected[i] == id_actual[i])
if not all(res): if not all(res):
print('input: %s' % input.rjust(20)) print('input: %s' % input.rjust(20))
@ -115,25 +115,25 @@ def _check(name, input, idDict, output, key, asTextOutput):
if res[i]: if res[i]:
continue continue
print('Error in id version %d.' % i) print('Error in id version %d.' % i)
print('result: %s' % idActual[i]) print('result: %s' % id_actual[i])
print('expected: %s' % idExpected[i]) print('expected: %s' % id_expected[i])
print(rootSymbol.dump(0)) print(root_symbol.dump(0))
raise DefinitionError raise DefinitionError
def check(name, input, idDict, output=None, key=None, asTextOutput=None): def check(name, input, id_dict, output=None, key=None, as_text_output=None):
if output is None: if output is None:
output = input output = input
# First, check without semicolon # First, check without semicolon
_check(name, input, idDict, output, key, asTextOutput) _check(name, input, id_dict, output, key, as_text_output)
# Second, check with semicolon # Second, check with semicolon
_check( _check(
name, name,
input + ' ;', input + ' ;',
idDict, id_dict,
output + ';', output + ';',
key, key,
asTextOutput + ';' if asTextOutput is not None else None, as_text_output + ';' if as_text_output is not None else None,
) )
@ -177,13 +177,13 @@ def test_domain_cpp_ast_fundamental_types(type_, id_v2):
def test_domain_cpp_ast_expressions(): def test_domain_cpp_ast_expressions():
def exprCheck(expr, id, id4=None): def expr_check(expr, id, id4=None):
ids = 'IE1CIA%s_1aE' ids = 'IE1CIA%s_1aE'
# call .format() on the expr to unescape double curly braces # call .format() on the expr to unescape double curly braces
idDict = {2: ids % expr.format(), 3: ids % id} id_dict = {2: ids % expr.format(), 3: ids % id}
if id4 is not None: if id4 is not None:
idDict[4] = ids % id4 id_dict[4] = ids % id4
check('class', 'template<> {key}C<a[%s]>' % expr, idDict) check('class', 'template<> {key}C<a[%s]>' % expr, id_dict)
class Config: class Config:
cpp_id_attributes = ['id_attr'] cpp_id_attributes = ['id_attr']
@ -198,19 +198,19 @@ def test_domain_cpp_ast_expressions():
print('Input: ', expr) print('Input: ', expr)
print('Result: ', res) print('Result: ', res)
raise DefinitionError raise DefinitionError
displayString = ast.get_display_string() display_string = ast.get_display_string()
if res != displayString: if res != display_string:
# note: if the expression contains an anon name then this will trigger a falsely # note: if the expression contains an anon name then this will trigger a falsely
print() print()
print('Input: ', expr) print('Input: ', expr)
print('Result: ', res) print('Result: ', res)
print('Display: ', displayString) print('Display: ', display_string)
raise DefinitionError raise DefinitionError
# primary # primary
exprCheck('nullptr', 'LDnE') expr_check('nullptr', 'LDnE')
exprCheck('true', 'L1E') expr_check('true', 'L1E')
exprCheck('false', 'L0E') expr_check('false', 'L0E')
ints = [ ints = [
'5', '5',
'0', '0',
@ -224,16 +224,16 @@ def test_domain_cpp_ast_expressions():
"0x0'1'2", "0x0'1'2",
"1'2'3", "1'2'3",
] ]
unsignedSuffix = ['', 'u', 'U'] unsigned_suffix = ['', 'u', 'U']
longSuffix = ['', 'l', 'L', 'll', 'LL'] long_suffix = ['', 'l', 'L', 'll', 'LL']
for i in ints: for i in ints:
for u in unsignedSuffix: for u in unsigned_suffix:
for l in longSuffix: for l in long_suffix:
expr = i + u + l expr = i + u + l
exprCheck(expr, 'L' + expr.replace("'", '') + 'E') expr_check(expr, 'L' + expr.replace("'", '') + 'E')
expr = i + l + u expr = i + l + u
exprCheck(expr, 'L' + expr.replace("'", '') + 'E') expr_check(expr, 'L' + expr.replace("'", '') + 'E')
decimalFloats = [ decimal_floats = [
'5e42', '5e42',
'5e+42', '5e+42',
'5e-42', '5e-42',
@ -254,7 +254,7 @@ def test_domain_cpp_ast_expressions():
".4'5'6e7'8'9", ".4'5'6e7'8'9",
"1'2'3.4'5'6e7'8'9", "1'2'3.4'5'6e7'8'9",
] ]
hexFloats = [ hex_floats = [
'ApF', 'ApF',
'Ap+F', 'Ap+F',
'Ap-F', 'Ap-F',
@ -276,16 +276,16 @@ def test_domain_cpp_ast_expressions():
"A'B'C.D'E'Fp1'2'3", "A'B'C.D'E'Fp1'2'3",
] ]
for suffix in ('', 'f', 'F', 'l', 'L'): for suffix in ('', 'f', 'F', 'l', 'L'):
for e in decimalFloats: for e in decimal_floats:
expr = e + suffix expr = e + suffix
exprCheck(expr, 'L' + expr.replace("'", '') + 'E') expr_check(expr, 'L' + expr.replace("'", '') + 'E')
for e in hexFloats: for e in hex_floats:
expr = '0x' + e + suffix expr = '0x' + e + suffix
exprCheck(expr, 'L' + expr.replace("'", '') + 'E') expr_check(expr, 'L' + expr.replace("'", '') + 'E')
exprCheck('"abc\\"cba"', 'LA8_KcE') # string expr_check('"abc\\"cba"', 'LA8_KcE') # string
exprCheck('this', 'fpT') expr_check('this', 'fpT')
# character literals # character literals
charPrefixAndIds = [('', 'c'), ('u8', 'c'), ('u', 'Ds'), ('U', 'Di'), ('L', 'w')] char_prefix_and_ids = [('', 'c'), ('u8', 'c'), ('u', 'Ds'), ('U', 'Di'), ('L', 'w')]
chars = [ chars = [
('a', '97'), ('a', '97'),
('\\n', '10'), ('\\n', '10'),
@ -298,156 +298,156 @@ def test_domain_cpp_ast_expressions():
('\\U0001f34c', '127820'), ('\\U0001f34c', '127820'),
('\\U0001F34C', '127820'), ('\\U0001F34C', '127820'),
] ]
for p, t in charPrefixAndIds: for p, t in char_prefix_and_ids:
for c, val in chars: for c, val in chars:
exprCheck(f"{p}'{c}'", t + val) expr_check(f"{p}'{c}'", t + val)
# user-defined literals # user-defined literals
for i in ints: for i in ints:
exprCheck(i + '_udl', 'clL_Zli4_udlEL' + i.replace("'", '') + 'EE') expr_check(i + '_udl', 'clL_Zli4_udlEL' + i.replace("'", '') + 'EE')
exprCheck(i + 'uludl', 'clL_Zli5uludlEL' + i.replace("'", '') + 'EE') expr_check(i + 'uludl', 'clL_Zli5uludlEL' + i.replace("'", '') + 'EE')
for f in decimalFloats: for f in decimal_floats:
exprCheck(f + '_udl', 'clL_Zli4_udlEL' + f.replace("'", '') + 'EE') expr_check(f + '_udl', 'clL_Zli4_udlEL' + f.replace("'", '') + 'EE')
exprCheck(f + 'fudl', 'clL_Zli4fudlEL' + f.replace("'", '') + 'EE') expr_check(f + 'fudl', 'clL_Zli4fudlEL' + f.replace("'", '') + 'EE')
for f in hexFloats: for f in hex_floats:
exprCheck('0x' + f + '_udl', 'clL_Zli4_udlEL0x' + f.replace("'", '') + 'EE') expr_check('0x' + f + '_udl', 'clL_Zli4_udlEL0x' + f.replace("'", '') + 'EE')
for p, t in charPrefixAndIds: for p, t in char_prefix_and_ids:
for c, val in chars: for c, val in chars:
exprCheck(f"{p}'{c}'_udl", 'clL_Zli4_udlE' + t + val + 'E') expr_check(f"{p}'{c}'_udl", 'clL_Zli4_udlE' + t + val + 'E')
exprCheck('"abc"_udl', 'clL_Zli4_udlELA3_KcEE') expr_check('"abc"_udl', 'clL_Zli4_udlELA3_KcEE')
# from issue #7294 # from issue #7294
exprCheck('6.62607015e-34q_J', 'clL_Zli3q_JEL6.62607015e-34EE') expr_check('6.62607015e-34q_J', 'clL_Zli3q_JEL6.62607015e-34EE')
# fold expressions, paren, name # fold expressions, paren, name
exprCheck('(... + Ns)', '(... + Ns)', id4='flpl2Ns') expr_check('(... + Ns)', '(... + Ns)', id4='flpl2Ns')
exprCheck('(Ns + ...)', '(Ns + ...)', id4='frpl2Ns') expr_check('(Ns + ...)', '(Ns + ...)', id4='frpl2Ns')
exprCheck('(Ns + ... + 0)', '(Ns + ... + 0)', id4='fLpl2NsL0E') expr_check('(Ns + ... + 0)', '(Ns + ... + 0)', id4='fLpl2NsL0E')
exprCheck('(5)', 'L5E') expr_check('(5)', 'L5E')
exprCheck('C', '1C') expr_check('C', '1C')
# postfix # postfix
exprCheck('A(2)', 'cl1AL2EE') expr_check('A(2)', 'cl1AL2EE')
exprCheck('A[2]', 'ix1AL2E') expr_check('A[2]', 'ix1AL2E')
exprCheck('a.b.c', 'dtdt1a1b1c') expr_check('a.b.c', 'dtdt1a1b1c')
exprCheck('a->b->c', 'ptpt1a1b1c') expr_check('a->b->c', 'ptpt1a1b1c')
exprCheck('i++', 'pp1i') expr_check('i++', 'pp1i')
exprCheck('i--', 'mm1i') expr_check('i--', 'mm1i')
exprCheck('dynamic_cast<T&>(i)++', 'ppdcR1T1i') expr_check('dynamic_cast<T&>(i)++', 'ppdcR1T1i')
exprCheck('static_cast<T&>(i)++', 'ppscR1T1i') expr_check('static_cast<T&>(i)++', 'ppscR1T1i')
exprCheck('reinterpret_cast<T&>(i)++', 'pprcR1T1i') expr_check('reinterpret_cast<T&>(i)++', 'pprcR1T1i')
exprCheck('const_cast<T&>(i)++', 'ppccR1T1i') expr_check('const_cast<T&>(i)++', 'ppccR1T1i')
exprCheck('typeid(T).name', 'dtti1T4name') expr_check('typeid(T).name', 'dtti1T4name')
exprCheck('typeid(a + b).name', 'dttepl1a1b4name') expr_check('typeid(a + b).name', 'dttepl1a1b4name')
# unary # unary
exprCheck('++5', 'pp_L5E') expr_check('++5', 'pp_L5E')
exprCheck('--5', 'mm_L5E') expr_check('--5', 'mm_L5E')
exprCheck('*5', 'deL5E') expr_check('*5', 'deL5E')
exprCheck('&5', 'adL5E') expr_check('&5', 'adL5E')
exprCheck('+5', 'psL5E') expr_check('+5', 'psL5E')
exprCheck('-5', 'ngL5E') expr_check('-5', 'ngL5E')
exprCheck('!5', 'ntL5E') expr_check('!5', 'ntL5E')
exprCheck('not 5', 'ntL5E') expr_check('not 5', 'ntL5E')
exprCheck('~5', 'coL5E') expr_check('~5', 'coL5E')
exprCheck('compl 5', 'coL5E') expr_check('compl 5', 'coL5E')
exprCheck('sizeof...(a)', 'sZ1a') expr_check('sizeof...(a)', 'sZ1a')
exprCheck('sizeof(T)', 'st1T') expr_check('sizeof(T)', 'st1T')
exprCheck('sizeof -42', 'szngL42E') expr_check('sizeof -42', 'szngL42E')
exprCheck('alignof(T)', 'at1T') expr_check('alignof(T)', 'at1T')
exprCheck('noexcept(-42)', 'nxngL42E') expr_check('noexcept(-42)', 'nxngL42E')
# new-expression # new-expression
exprCheck('new int', 'nw_iE') expr_check('new int', 'nw_iE')
exprCheck('new volatile int', 'nw_ViE') expr_check('new volatile int', 'nw_ViE')
exprCheck('new int[42]', 'nw_AL42E_iE') expr_check('new int[42]', 'nw_AL42E_iE')
exprCheck('new int()', 'nw_ipiE') expr_check('new int()', 'nw_ipiE')
exprCheck('new int(5, 42)', 'nw_ipiL5EL42EE') expr_check('new int(5, 42)', 'nw_ipiL5EL42EE')
exprCheck('::new int', 'nw_iE') expr_check('::new int', 'nw_iE')
exprCheck('new int{{}}', 'nw_iilE') expr_check('new int{{}}', 'nw_iilE')
exprCheck('new int{{5, 42}}', 'nw_iilL5EL42EE') expr_check('new int{{5, 42}}', 'nw_iilL5EL42EE')
# delete-expression # delete-expression
exprCheck('delete p', 'dl1p') expr_check('delete p', 'dl1p')
exprCheck('delete [] p', 'da1p') expr_check('delete [] p', 'da1p')
exprCheck('::delete p', 'dl1p') expr_check('::delete p', 'dl1p')
exprCheck('::delete [] p', 'da1p') expr_check('::delete [] p', 'da1p')
# cast # cast
exprCheck('(int)2', 'cviL2E') expr_check('(int)2', 'cviL2E')
# binary op # binary op
exprCheck('5 || 42', 'ooL5EL42E') expr_check('5 || 42', 'ooL5EL42E')
exprCheck('5 or 42', 'ooL5EL42E') expr_check('5 or 42', 'ooL5EL42E')
exprCheck('5 && 42', 'aaL5EL42E') expr_check('5 && 42', 'aaL5EL42E')
exprCheck('5 and 42', 'aaL5EL42E') expr_check('5 and 42', 'aaL5EL42E')
exprCheck('5 | 42', 'orL5EL42E') expr_check('5 | 42', 'orL5EL42E')
exprCheck('5 bitor 42', 'orL5EL42E') expr_check('5 bitor 42', 'orL5EL42E')
exprCheck('5 ^ 42', 'eoL5EL42E') expr_check('5 ^ 42', 'eoL5EL42E')
exprCheck('5 xor 42', 'eoL5EL42E') expr_check('5 xor 42', 'eoL5EL42E')
exprCheck('5 & 42', 'anL5EL42E') expr_check('5 & 42', 'anL5EL42E')
exprCheck('5 bitand 42', 'anL5EL42E') expr_check('5 bitand 42', 'anL5EL42E')
# ['==', '!='] # ['==', '!=']
exprCheck('5 == 42', 'eqL5EL42E') expr_check('5 == 42', 'eqL5EL42E')
exprCheck('5 != 42', 'neL5EL42E') expr_check('5 != 42', 'neL5EL42E')
exprCheck('5 not_eq 42', 'neL5EL42E') expr_check('5 not_eq 42', 'neL5EL42E')
# ['<=', '>=', '<', '>', '<=>'] # ['<=', '>=', '<', '>', '<=>']
exprCheck('5 <= 42', 'leL5EL42E') expr_check('5 <= 42', 'leL5EL42E')
exprCheck('A <= 42', 'le1AL42E') expr_check('A <= 42', 'le1AL42E')
exprCheck('5 >= 42', 'geL5EL42E') expr_check('5 >= 42', 'geL5EL42E')
exprCheck('5 < 42', 'ltL5EL42E') expr_check('5 < 42', 'ltL5EL42E')
exprCheck('A < 42', 'lt1AL42E') expr_check('A < 42', 'lt1AL42E')
exprCheck('5 > 42', 'gtL5EL42E') expr_check('5 > 42', 'gtL5EL42E')
exprCheck('A > 42', 'gt1AL42E') expr_check('A > 42', 'gt1AL42E')
exprCheck('5 <=> 42', 'ssL5EL42E') expr_check('5 <=> 42', 'ssL5EL42E')
exprCheck('A <=> 42', 'ss1AL42E') expr_check('A <=> 42', 'ss1AL42E')
# ['<<', '>>'] # ['<<', '>>']
exprCheck('5 << 42', 'lsL5EL42E') expr_check('5 << 42', 'lsL5EL42E')
exprCheck('A << 42', 'ls1AL42E') expr_check('A << 42', 'ls1AL42E')
exprCheck('5 >> 42', 'rsL5EL42E') expr_check('5 >> 42', 'rsL5EL42E')
# ['+', '-'] # ['+', '-']
exprCheck('5 + 42', 'plL5EL42E') expr_check('5 + 42', 'plL5EL42E')
exprCheck('5 - 42', 'miL5EL42E') expr_check('5 - 42', 'miL5EL42E')
# ['*', '/', '%'] # ['*', '/', '%']
exprCheck('5 * 42', 'mlL5EL42E') expr_check('5 * 42', 'mlL5EL42E')
exprCheck('5 / 42', 'dvL5EL42E') expr_check('5 / 42', 'dvL5EL42E')
exprCheck('5 % 42', 'rmL5EL42E') expr_check('5 % 42', 'rmL5EL42E')
# ['.*', '->*'] # ['.*', '->*']
exprCheck('5 .* 42', 'dsL5EL42E') expr_check('5 .* 42', 'dsL5EL42E')
exprCheck('5 ->* 42', 'pmL5EL42E') expr_check('5 ->* 42', 'pmL5EL42E')
# conditional # conditional
exprCheck('5 ? 7 : 3', 'quL5EL7EL3E') expr_check('5 ? 7 : 3', 'quL5EL7EL3E')
# assignment # assignment
exprCheck('a = 5', 'aS1aL5E') expr_check('a = 5', 'aS1aL5E')
exprCheck('a *= 5', 'mL1aL5E') expr_check('a *= 5', 'mL1aL5E')
exprCheck('a /= 5', 'dV1aL5E') expr_check('a /= 5', 'dV1aL5E')
exprCheck('a %= 5', 'rM1aL5E') expr_check('a %= 5', 'rM1aL5E')
exprCheck('a += 5', 'pL1aL5E') expr_check('a += 5', 'pL1aL5E')
exprCheck('a -= 5', 'mI1aL5E') expr_check('a -= 5', 'mI1aL5E')
exprCheck('a >>= 5', 'rS1aL5E') expr_check('a >>= 5', 'rS1aL5E')
exprCheck('a <<= 5', 'lS1aL5E') expr_check('a <<= 5', 'lS1aL5E')
exprCheck('a &= 5', 'aN1aL5E') expr_check('a &= 5', 'aN1aL5E')
exprCheck('a and_eq 5', 'aN1aL5E') expr_check('a and_eq 5', 'aN1aL5E')
exprCheck('a ^= 5', 'eO1aL5E') expr_check('a ^= 5', 'eO1aL5E')
exprCheck('a xor_eq 5', 'eO1aL5E') expr_check('a xor_eq 5', 'eO1aL5E')
exprCheck('a |= 5', 'oR1aL5E') expr_check('a |= 5', 'oR1aL5E')
exprCheck('a or_eq 5', 'oR1aL5E') expr_check('a or_eq 5', 'oR1aL5E')
exprCheck('a = {{1, 2, 3}}', 'aS1ailL1EL2EL3EE') expr_check('a = {{1, 2, 3}}', 'aS1ailL1EL2EL3EE')
# complex assignment and conditional # complex assignment and conditional
exprCheck('5 = 6 = 7', 'aSL5EaSL6EL7E') expr_check('5 = 6 = 7', 'aSL5EaSL6EL7E')
exprCheck('5 = 6 ? 7 = 8 : 3', 'aSL5EquL6EaSL7EL8EL3E') expr_check('5 = 6 ? 7 = 8 : 3', 'aSL5EquL6EaSL7EL8EL3E')
# comma operator # comma operator
exprCheck('a, 5', 'cm1aL5E') expr_check('a, 5', 'cm1aL5E')
# Additional tests # Additional tests
# a < expression that starts with something that could be a template # a < expression that starts with something that could be a template
exprCheck('A < 42', 'lt1AL42E') expr_check('A < 42', 'lt1AL42E')
check( check(
'function', 'function',
'template<> void f(A<B, 2> &v)', 'template<> void f(A<B, 2> &v)',
{2: 'IE1fR1AI1BX2EE', 3: 'IE1fR1AI1BXL2EEE', 4: 'IE1fvR1AI1BXL2EEE'}, {2: 'IE1fR1AI1BX2EE', 3: 'IE1fR1AI1BXL2EEE', 4: 'IE1fvR1AI1BXL2EEE'},
) )
exprCheck('A<1>::value', 'N1AIXL1EEE5valueE') expr_check('A<1>::value', 'N1AIXL1EEE5valueE')
check('class', 'template<int T = 42> {key}A', {2: 'I_iE1A'}) check('class', 'template<int T = 42> {key}A', {2: 'I_iE1A'})
check('enumerator', '{key}A = std::numeric_limits<unsigned long>::max()', {2: '1A'}) check('enumerator', '{key}A = std::numeric_limits<unsigned long>::max()', {2: '1A'})
exprCheck('operator()()', 'clclE') expr_check('operator()()', 'clclE')
exprCheck('operator()<int>()', 'clclIiEE') expr_check('operator()<int>()', 'clclIiEE')
# pack expansion # pack expansion
exprCheck('a(b(c, 1 + d...)..., e(f..., g))', 'cl1aspcl1b1cspplL1E1dEcl1esp1f1gEE') expr_check('a(b(c, 1 + d...)..., e(f..., g))', 'cl1aspcl1b1cspplL1E1dEcl1esp1f1gEE')
def test_domain_cpp_ast_type_definitions(): def test_domain_cpp_ast_type_definitions():
@ -1062,17 +1062,17 @@ def test_domain_cpp_ast_enum_definitions():
def test_domain_cpp_ast_anon_definitions(): def test_domain_cpp_ast_anon_definitions():
check('class', '@a', {3: 'Ut1_a'}, asTextOutput='class [anonymous]') check('class', '@a', {3: 'Ut1_a'}, as_text_output='class [anonymous]')
check('union', '@a', {3: 'Ut1_a'}, asTextOutput='union [anonymous]') check('union', '@a', {3: 'Ut1_a'}, as_text_output='union [anonymous]')
check('enum', '@a', {3: 'Ut1_a'}, asTextOutput='enum [anonymous]') check('enum', '@a', {3: 'Ut1_a'}, as_text_output='enum [anonymous]')
check('class', '@1', {3: 'Ut1_1'}, asTextOutput='class [anonymous]') check('class', '@1', {3: 'Ut1_1'}, as_text_output='class [anonymous]')
check('class', '@a::A', {3: 'NUt1_a1AE'}, asTextOutput='class [anonymous]::A') check('class', '@a::A', {3: 'NUt1_a1AE'}, as_text_output='class [anonymous]::A')
check( check(
'function', 'function',
'int f(int @a)', 'int f(int @a)',
{1: 'f__i', 2: '1fi'}, {1: 'f__i', 2: '1fi'},
asTextOutput='int f(int [anonymous])', as_text_output='int f(int [anonymous])',
) )
@ -1370,37 +1370,37 @@ def test_domain_cpp_ast_template_args():
def test_domain_cpp_ast_initializers(): def test_domain_cpp_ast_initializers():
idsMember = {1: 'v__T', 2: '1v'} ids_member = {1: 'v__T', 2: '1v'}
idsFunction = {1: 'f__T', 2: '1f1T'} ids_function = {1: 'f__T', 2: '1f1T'}
idsTemplate = {2: 'I_1TE1fv', 4: 'I_1TE1fvv'} ids_template = {2: 'I_1TE1fv', 4: 'I_1TE1fvv'}
# no init # no init
check('member', 'T v', idsMember) check('member', 'T v', ids_member)
check('function', 'void f(T v)', idsFunction) check('function', 'void f(T v)', ids_function)
check('function', 'template<T v> void f()', idsTemplate) check('function', 'template<T v> void f()', ids_template)
# with '=', assignment-expression # with '=', assignment-expression
check('member', 'T v = 42', idsMember) check('member', 'T v = 42', ids_member)
check('function', 'void f(T v = 42)', idsFunction) check('function', 'void f(T v = 42)', ids_function)
check('function', 'template<T v = 42> void f()', idsTemplate) check('function', 'template<T v = 42> void f()', ids_template)
# with '=', braced-init # with '=', braced-init
check('member', 'T v = {}', idsMember) check('member', 'T v = {}', ids_member)
check('function', 'void f(T v = {})', idsFunction) check('function', 'void f(T v = {})', ids_function)
check('function', 'template<T v = {}> void f()', idsTemplate) check('function', 'template<T v = {}> void f()', ids_template)
check('member', 'T v = {42, 42, 42}', idsMember) check('member', 'T v = {42, 42, 42}', ids_member)
check('function', 'void f(T v = {42, 42, 42})', idsFunction) check('function', 'void f(T v = {42, 42, 42})', ids_function)
check('function', 'template<T v = {42, 42, 42}> void f()', idsTemplate) check('function', 'template<T v = {42, 42, 42}> void f()', ids_template)
check('member', 'T v = {42, 42, 42,}', idsMember) check('member', 'T v = {42, 42, 42,}', ids_member)
check('function', 'void f(T v = {42, 42, 42,})', idsFunction) check('function', 'void f(T v = {42, 42, 42,})', ids_function)
check('function', 'template<T v = {42, 42, 42,}> void f()', idsTemplate) check('function', 'template<T v = {42, 42, 42,}> void f()', ids_template)
check('member', 'T v = {42, 42, args...}', idsMember) check('member', 'T v = {42, 42, args...}', ids_member)
check('function', 'void f(T v = {42, 42, args...})', idsFunction) check('function', 'void f(T v = {42, 42, args...})', ids_function)
check('function', 'template<T v = {42, 42, args...}> void f()', idsTemplate) check('function', 'template<T v = {42, 42, args...}> void f()', ids_template)
# without '=', braced-init # without '=', braced-init
check('member', 'T v{}', idsMember) check('member', 'T v{}', ids_member)
check('member', 'T v{42, 42, 42}', idsMember) check('member', 'T v{42, 42, 42}', ids_member)
check('member', 'T v{42, 42, 42,}', idsMember) check('member', 'T v{42, 42, 42,}', ids_member)
check('member', 'T v{42, 42, args...}', idsMember) check('member', 'T v{42, 42, args...}', ids_member)
# other # other
check('member', 'T v = T{}', idsMember) check('member', 'T v = T{}', ids_member)
def test_domain_cpp_ast_attributes(): def test_domain_cpp_ast_attributes():
@ -1606,7 +1606,7 @@ def test_domain_cpp_build_misuse_of_roles(app):
ws = filter_warnings(app.warning, 'roles-targets-warn') ws = filter_warnings(app.warning, 'roles-targets-warn')
# the roles that should be able to generate warnings: # the roles that should be able to generate warnings:
allRoles = [ all_roles = [
'class', 'class',
'struct', 'struct',
'union', 'union',
@ -1618,7 +1618,7 @@ def test_domain_cpp_build_misuse_of_roles(app):
'enum', 'enum',
'enumerator', 'enumerator',
] ]
ok = [ # targetType, okRoles ok = [ # target_type, ok_roles
('class', ['class', 'struct', 'type']), ('class', ['class', 'struct', 'type']),
('union', ['union', 'type']), ('union', ['union', 'type']),
('func', ['func', 'type']), ('func', ['func', 'type']),
@ -1631,14 +1631,14 @@ def test_domain_cpp_build_misuse_of_roles(app):
('templateParam', ['class', 'struct', 'union', 'member', 'var', 'type']), ('templateParam', ['class', 'struct', 'union', 'member', 'var', 'type']),
] ]
warn = [] warn = []
for targetType, roles in ok: for target_type, roles in ok:
txtTargetType = 'function' if targetType == 'func' else targetType txt_target_type = 'function' if target_type == 'func' else target_type
for r in allRoles: for r in all_roles:
if r not in roles: if r not in roles:
warn.append(f'WARNING: cpp:{r} targets a {txtTargetType} (') warn.append(f'WARNING: cpp:{r} targets a {txt_target_type} (')
if targetType == 'templateParam': if target_type == 'templateParam':
warn.append(f'WARNING: cpp:{r} targets a {txtTargetType} (') warn.append(f'WARNING: cpp:{r} targets a {txt_target_type} (')
warn.append(f'WARNING: cpp:{r} targets a {txtTargetType} (') warn.append(f'WARNING: cpp:{r} targets a {txt_target_type} (')
warn = sorted(warn) warn = sorted(warn)
for w in ws: for w in ws:
assert 'targets a' in w assert 'targets a' in w
@ -1665,14 +1665,14 @@ def test_domain_cpp_build_misuse_of_roles(app):
def test_domain_cpp_build_with_add_function_parentheses_is_True(app): def test_domain_cpp_build_with_add_function_parentheses_is_True(app):
app.build(force_all=True) app.build(force_all=True)
rolePatterns = [ role_patterns = [
'Sphinx', 'Sphinx',
'Sphinx::version', 'Sphinx::version',
'version', 'version',
'List', 'List',
'MyEnum', 'MyEnum',
] ]
parenPatterns = [ paren_patterns = [
('ref function without parens ', r'paren_1\(\)'), ('ref function without parens ', r'paren_1\(\)'),
('ref function with parens ', r'paren_2\(\)'), ('ref function with parens ', r'paren_2\(\)'),
('ref function without parens, explicit title ', 'paren_3_title'), ('ref function without parens, explicit title ', 'paren_3_title'),
@ -1684,19 +1684,19 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app):
] ]
text = (app.outdir / 'roles.html').read_text(encoding='utf8') text = (app.outdir / 'roles.html').read_text(encoding='utf8')
for ref_text in rolePatterns: for ref_text in role_patterns:
pattern = ( pattern = (
f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>' f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
) )
match = re.search(pattern, text) match = re.search(pattern, text)
assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}' assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}'
for desc_text, ref_text in parenPatterns: for desc_text, ref_text in paren_patterns:
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>' pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
match = re.search(pattern, text) match = re.search(pattern, text)
assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}' assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}'
text = (app.outdir / 'any-role.html').read_text(encoding='utf8') text = (app.outdir / 'any-role.html').read_text(encoding='utf8')
for desc_text, ref_text in parenPatterns: for desc_text, ref_text in paren_patterns:
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>' pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
match = re.search(pattern, text) match = re.search(pattern, text)
assert match is not None, f'Pattern not found in any-role.html:\n\t{pattern}' assert match is not None, f'Pattern not found in any-role.html:\n\t{pattern}'
@ -1710,14 +1710,14 @@ def test_domain_cpp_build_with_add_function_parentheses_is_True(app):
def test_domain_cpp_build_with_add_function_parentheses_is_False(app): def test_domain_cpp_build_with_add_function_parentheses_is_False(app):
app.build(force_all=True) app.build(force_all=True)
rolePatterns = [ role_patterns = [
'Sphinx', 'Sphinx',
'Sphinx::version', 'Sphinx::version',
'version', 'version',
'List', 'List',
'MyEnum', 'MyEnum',
] ]
parenPatterns = [ paren_patterns = [
('ref function without parens ', 'paren_1'), ('ref function without parens ', 'paren_1'),
('ref function with parens ', 'paren_2'), ('ref function with parens ', 'paren_2'),
('ref function without parens, explicit title ', 'paren_3_title'), ('ref function without parens, explicit title ', 'paren_3_title'),
@ -1729,19 +1729,19 @@ def test_domain_cpp_build_with_add_function_parentheses_is_False(app):
] ]
text = (app.outdir / 'roles.html').read_text(encoding='utf8') text = (app.outdir / 'roles.html').read_text(encoding='utf8')
for ref_text in rolePatterns: for ref_text in role_patterns:
pattern = ( pattern = (
f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>' f'<li><p><a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
) )
match = re.search(pattern, text) match = re.search(pattern, text)
assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}' assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}'
for desc_text, ref_text in parenPatterns: for desc_text, ref_text in paren_patterns:
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>' pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
match = re.search(pattern, text) match = re.search(pattern, text)
assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}' assert match is not None, f'Pattern not found in roles.html:\n\t{pattern}'
text = (app.outdir / 'any-role.html').read_text(encoding='utf8') text = (app.outdir / 'any-role.html').read_text(encoding='utf8')
for desc_text, ref_text in parenPatterns: for desc_text, ref_text in paren_patterns:
pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>' pattern = f'<li><p>{desc_text}<a .*?><code .*?><span .*?>{ref_text}</span></code></a></p></li>'
match = re.search(pattern, text) match = re.search(pattern, text)
assert match is not None, f'Pattern not found in any-role.html:\n\t{pattern}' assert match is not None, f'Pattern not found in any-role.html:\n\t{pattern}'
@ -1843,7 +1843,7 @@ def test_domain_cpp_build_operator_lookup(app):
'html', testroot='domain-cpp-intersphinx', confoverrides={'nitpicky': True} 'html', testroot='domain-cpp-intersphinx', confoverrides={'nitpicky': True}
) )
def test_domain_cpp_build_intersphinx(tmp_path, app): def test_domain_cpp_build_intersphinx(tmp_path, app):
origSource = """\ orig_source = """\
.. cpp:class:: _class .. cpp:class:: _class
.. cpp:struct:: _struct .. cpp:struct:: _struct
.. cpp:union:: _union .. cpp:union:: _union

View File

@ -522,8 +522,8 @@ def test_productionlist(app):
assert len(code_list) == 1 assert len(code_list) == 1
span = code_list[0] span = code_list[0]
assert span.tag == 'span' assert span.tag == 'span'
linkText = span.text.strip() link_text = span.text.strip()
cases.append((text, link, linkText)) cases.append((text, link, link_text))
assert cases == [ assert cases == [
('A', 'Bare.html#grammar-token-A', 'A'), ('A', 'Bare.html#grammar-token-A', 'A'),
('B', 'Bare.html#grammar-token-B', 'B'), ('B', 'Bare.html#grammar-token-B', 'B'),