[gtk-doc] scan: add more tests for function pointer typedefs
- From: Stefan Sauer <stefkost src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-doc] scan: add more tests for function pointer typedefs
- Date: Thu, 13 Dec 2018 19:02:33 +0000 (UTC)
commit 302e71d709735f31b52f4737a512312b2041f708
Author: Stefan Sauer <ensonic users sf net>
Date: Wed Dec 12 21:01:11 2018 +0100
scan: add more tests for function pointer typedefs
Fix handling of struct * return values and trim whitespace.
gtkdoc/scan.py | 11 +++++++++--
tests/scan.py | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/gtkdoc/scan.py b/gtkdoc/scan.py
index afbd9f4..dc1f140 100644
--- a/gtkdoc/scan.py
+++ b/gtkdoc/scan.py
@@ -149,6 +149,7 @@ PLINE_MATCHER = [
r"""^\s*typedef\s*
(%s\w+) # 1: return type
(\s+const)?\s* # 2: 2nd const
+ (\**)\s* # 3: ptr
""" % RET_TYPE_MODIFIER, re.VERBOSE),
re.compile(r'^\s*typedef\s*'),
# 2-5 :FUNCTIONS
@@ -632,7 +633,7 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options):
symbol = cm[3].group(2)
decl = line[cm[3].end():]
if pm[0]:
- ret_type = format_ret_type(pm[0].group(1), pm[0].group(2), ret_type)
+ ret_type = format_ret_type(pm[0].group(1), pm[0].group(2), pm[0].group(3)) + ret_type
in_declaration = 'user_function'
logging.info('user function (3): "%s", Returns: "%s"', symbol, ret_type)
@@ -934,7 +935,7 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options):
logging.info('scrubbed:[%s]', decl.strip())
if internal == 0:
decl = re.sub(r'/\*.*?\*/', '', decl, flags=re.MULTILINE) # remove comments.
- decl = re.sub(r'\s*\n\s*(?!$)', ' ', decl, flags=re.MULTILINE)
+ decl = re.sub(r'\s*\n\s*(?!$)', ' ', decl, flags=re.MULTILINE) # remove newlines
# consolidate whitespace at start/end of lines.
decl = decl.strip()
ret_type = re.sub(r'/\*.*?\*/', '', ret_type).strip() # remove comments in ret
type.
@@ -956,6 +957,12 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options):
if in_declaration == 'user_function':
if re.search(r'\).*$', decl):
decl = re.sub(r'\).*$', '', decl)
+ # TODO: same as above
+ decl = re.sub(r'/\*.*?\*/', '', decl, flags=re.MULTILINE) # remove comments.
+ decl = re.sub(r'\s*\n\s*(?!$)', ' ', decl, flags=re.MULTILINE) # remove newlines
+ # TODO: don't stip here (it works above, but fails some test
+ # consolidate whitespace at start/end of lines.
+ # decl = decl.strip()
if AddSymbolToList(slist, symbol):
decl_list.append('<USER_FUNCTION>\n<NAME>%s</NAME>\n%s<RETURNS>%s</RETURNS>\n%s</USER_FUNCTION>\n' %
(symbol, deprecated, ret_type, decl))
diff --git a/tests/scan.py b/tests/scan.py
index 6a2fbc5..62a6f60 100755
--- a/tests/scan.py
+++ b/tests/scan.py
@@ -425,6 +425,39 @@ class ScanHeaderContentUserFunction(ScanHeaderContentTestCase):
slist, doc_comments = self.scanHeaderContent([header])
self.assertDecl('func', 'const ' + ret_type + ' *', 'void', slist)
+ def test_FindsFunctionVoid_Int_WithLinebreakAfterTypedef(self):
+ header = textwrap.dedent("""\
+ typedef
+ void (*func) (int a);""")
+ slist, doc_comments = self.scanHeaderContent(
+ header.splitlines(keepends=True))
+ self.assertDecl('func', 'void', 'int a', slist)
+
+ def test_FindsFunctionStruct_Void_WithLinebreakAfterRetType(self):
+ header = textwrap.dedent("""\
+ typedef struct ret *
+ (*func) (void);""")
+ slist, doc_comments = self.scanHeaderContent(
+ header.splitlines(keepends=True))
+ self.assertDecl('func', 'struct ret *', 'void', slist)
+
+ # TODO: not found
+ # def test_FindsFunctionStruct_Void_WithLinebreakAfterFuncName(self):
+ # header = textwrap.dedent("""\
+ # typedef struct ret * (*func)
+ # (void);""")
+ # slist, doc_comments = self.scanHeaderContent(
+ # header.splitlines(keepends=True))
+ # self.assertDecl('func', 'struct ret *', 'void', slist)
+
+ def test_FindsFunctionVoid_Int_WithLinebreakAfterParamType(self):
+ header = textwrap.dedent("""\
+ typedef void (*func) (int
+ a);""")
+ slist, doc_comments = self.scanHeaderContent(
+ header.splitlines(keepends=True))
+ self.assertDecl('func', 'void', 'int a', slist)
+
class ScanHeaderContentVariabless(ScanHeaderContentTestCase):
"""Test parsing of variable declarations."""
@@ -470,4 +503,4 @@ if __name__ == '__main__':
#
# t = ScanHeaderContentUserFunction()
# t.setUp()
- # t.debug()
+ # t.test_FindsFunctionStruct_Void_WithLinebreakAfterRetType()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]