[gtk-doc] scan: add more coverage for functions



commit d47934ba84db92447efdd3eb67f4c244b155aa24
Author: Stefan Sauer <ensonic users sf net>
Date:   Tue Dec 11 15:39:59 2018 +0100

    scan: add more coverage for functions
    
    Normalize more whitespace output.

 gtkdoc/scan.py |  6 +++---
 tests/scan.py  | 13 ++++++++++---
 2 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/gtkdoc/scan.py b/gtkdoc/scan.py
index 4f5346a..2022102 100644
--- a/gtkdoc/scan.py
+++ b/gtkdoc/scan.py
@@ -502,8 +502,8 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options):
     PLINE_MATCHER[5] = re.compile(
         r"""^\s*(?:\b(?:extern|G_INLINE_FUNC%s)\s*)*
         (%s\w+)                                                     # 1: return type
-        (\s+\*+|\*+|\s)\s*
-        ([A-Za-z]\w*)
+        (\s+\*+|\*+|\s)\s*                                          # 2: ptr?
+        ([A-Za-z]\w*)                                               # 3: symbols
         \s*$""" % (ignore_decorators, RET_TYPE_MODIFIER), re.VERBOSE)
 
     for line in input_lines:
@@ -832,7 +832,7 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options):
                     )\s*$""" % ignore_decorators, pre_previous_line, re.VERBOSE)
 
                 if pm[5]:
-                    ret_type = pm[5].group(1) + ' ' + pm[5].group(2)
+                    ret_type = pm[5].group(1) + ' ' + pm[5].group(2).strip()
                     symbol = pm[5].group(3)
                     in_declaration = 'function'
                     logging.info('Function (5): "%s", Returns: "%s"', symbol, ret_type)
diff --git a/tests/scan.py b/tests/scan.py
index 8260b0f..ddc0a68 100644
--- a/tests/scan.py
+++ b/tests/scan.py
@@ -221,7 +221,7 @@ class ScanHeaderContentFunctions(ScanHeaderContentTestCase):
         slist, doc_comments = self.scanHeaderContent([header])
         self.assertDecl('func', 'int', 'char c, long l', slist)
 
-    def test_FindsFunctionStruct_Void(self):
+    def test_FindsFunctionStruct_Void_WithLinebreakAfterRetType(self):
         header = textwrap.dedent("""\
             struct ret *
             func (void);""")
@@ -229,7 +229,15 @@ class ScanHeaderContentFunctions(ScanHeaderContentTestCase):
             header.splitlines(keepends=True))
         self.assertDecl('func', 'struct ret *', 'void', slist)
 
-    def test_FindsFunctionVoid_IntWithLinebreak(self):
+    def test_FindsFunctionStruct_Void_WithLinebreakAfterFuncName(self):
+        header = textwrap.dedent("""\
+            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("""\
             void func (int
               a);""")
@@ -368,7 +376,6 @@ class ScanHeaderContentUnions(ScanHeaderContentTestCase):
         self.assertNoDeclFound(slist)
 
 
-# USER FUNCTION (aka function pointer types)
 class ScanHeaderContentUserFunction(ScanHeaderContentTestCase):
     """Test parsing of function pointer declarations."""
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]