summaryrefslogtreecommitdiff
path: root/tests/test_domain_c.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-06-30 21:24:06 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-06-30 21:24:06 +0900
commitec351bdf3d9405e664e8f793d3cddfa2fddfd07e (patch)
tree6f08294ce2daa5f6bd9e14ec7ad99cee0e30f639 /tests/test_domain_c.py
parent565c9536e50028937a723a92751eb04e82481653 (diff)
parent779d902359f6946be9326682de372d0e75a8cfd4 (diff)
downloadsphinx-git-ec351bdf3d9405e664e8f793d3cddfa2fddfd07e.tar.gz
Merge branch '4.0.x' into 4.x
Diffstat (limited to 'tests/test_domain_c.py')
-rw-r--r--tests/test_domain_c.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/tests/test_domain_c.py b/tests/test_domain_c.py
index 575b65362..d59c4fc1c 100644
--- a/tests/test_domain_c.py
+++ b/tests/test_domain_c.py
@@ -15,16 +15,20 @@ import pytest
from sphinx import addnodes
from sphinx.addnodes import desc
-from sphinx.domains.c import DefinitionError, DefinitionParser, Symbol, _id_prefix, _max_id
+from sphinx.domains.c import (DefinitionError, DefinitionParser, Symbol, _id_prefix,
+ _macroKeywords, _max_id)
from sphinx.ext.intersphinx import load_mappings, normalize_intersphinx_mapping
from sphinx.testing import restructuredtext
from sphinx.testing.util import assert_node
+class Config:
+ c_id_attributes = ["id_attr", 'LIGHTGBM_C_EXPORT']
+ c_paren_attributes = ["paren_attr"]
+ c_extra_keywords = _macroKeywords
+
+
def parse(name, string):
- class Config:
- c_id_attributes = ["id_attr", 'LIGHTGBM_C_EXPORT']
- c_paren_attributes = ["paren_attr"]
parser = DefinitionParser(string, location=None, config=Config())
parser.allowFallbackExpressionParsing = False
ast = parser.parse_declaration(name, name)
@@ -114,9 +118,6 @@ def check(name, input, idDict, output=None, key=None, asTextOutput=None):
def test_domain_c_ast_expressions():
def exprCheck(expr, output=None):
- class Config:
- c_id_attributes = ["id_attr"]
- c_paren_attributes = ["paren_attr"]
parser = DefinitionParser(expr, location=None, config=Config())
parser.allowFallbackExpressionParsing = False
ast = parser.parse_expression()
@@ -527,6 +528,16 @@ def test_domain_c_ast_attributes():
check('function', 'LIGHTGBM_C_EXPORT int LGBM_BoosterFree(int handle)',
{1: 'LGBM_BoosterFree'})
+
+def test_extra_keywords():
+ with pytest.raises(DefinitionError,
+ match='Expected identifier, got user-defined keyword: complex.'):
+ parse('function', 'void f(int complex)')
+ with pytest.raises(DefinitionError,
+ match='Expected identifier, got user-defined keyword: complex.'):
+ parse('function', 'void complex(void)')
+
+
# def test_print():
# # used for getting all the ids out for checking
# for a in ids: