[gtk-doc] scan: add parametrized tests for function pointers



commit f9aac88bb796a5211a5767db805a4e024daa1b0d
Author: Stefan Sauer <ensonic users sf net>
Date:   Sun Dec 9 19:39:04 2018 +0100

    scan: add parametrized tests for function pointers
    
    Support more variants in function pointer return types.

 gtkdoc/scan.py                      | 12 ++++++------
 tests/bugs/docs/tester-sections.txt |  1 -
 tests/bugs/src/tester.h             | 11 -----------
 tests/scan.py                       | 20 +++++++++++++++++++-
 4 files changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/gtkdoc/scan.py b/gtkdoc/scan.py
index 2243dc1..4f5346a 100644
--- a/gtkdoc/scan.py
+++ b/gtkdoc/scan.py
@@ -54,20 +54,20 @@ CLINE_MATCHER = [
     # 1-4: TYPEDEF'D FUNCTIONS
     re.compile(
         r"""^\s*typedef\s+
-        ((?:const\s+|G_CONST_RETURN\s+)?\w+) # 1: 1st const + type
+        (%s\w+)                              # 1: return type
         (\s+const)?\s*                       # 2: 2nd const
         (\**)\s*                             # 3: ptr
         \(\*\s*
           (\w+)                              # 4: name
-        \)\s*\(""", re.VERBOSE),
+        \)\s*\(""" % RET_TYPE_MODIFIER, re.VERBOSE),
     re.compile(
         r"""^\s*
-        ((?:const\s+|G_CONST_RETURN\s+)?\w+) # 1: 1st const
+        (%s?\w+)                             # 1: return type
         (\s+const)?\s*                       # 2: 2nd const
         (\**)\s*                             # 3: ptr
         \(\*\s*
           (\w+)                              # 4: name
-        \)\s*\(""", re.VERBOSE),
+        \)\s*\(""" % RET_TYPE_MODIFIER, re.VERBOSE),
     re.compile(
         r"""^\s*
         (\**)\s*                             # 1: ptr
@@ -147,9 +147,9 @@ PLINE_MATCHER = [
     # 0-1: TYPEDEF'D FUNCTIONS
     re.compile(
         r"""^\s*typedef\s*
-        ((?:const\s+|G_CONST_RETURN\s+)?\w+) # 1: 1st const
+        (%s\w+)                              # 1: return type
         (\s+const)?\s*                       # 2: 2nd const
-        """, re.VERBOSE),
+        """ % RET_TYPE_MODIFIER, re.VERBOSE),
     re.compile(r'^\s*typedef\s*'),
     # 2-5 :FUNCTIONS
     None,  # in ScanHeaderContent()
diff --git a/tests/bugs/docs/tester-sections.txt b/tests/bugs/docs/tester-sections.txt
index c39845c..c867e5b 100644
--- a/tests/bugs/docs/tester-sections.txt
+++ b/tests/bugs/docs/tester-sections.txt
@@ -28,7 +28,6 @@ bug_512155b_function_pointer_t
 bug_512155c_function_pointer_t
 bug_532395a
 bug_532395b
-bug_544172
 bug_554833
 bug_574654a
 bug_574654b
diff --git a/tests/bugs/src/tester.h b/tests/bugs/src/tester.h
index 7a7428f..46c361d 100644
--- a/tests/bugs/src/tester.h
+++ b/tests/bugs/src/tester.h
@@ -170,17 +170,6 @@ bug_532395b (void)
 }
 
 
-/**
- * bug_544172:
- * @self: object pointer.
- *
- * http://bugzilla.gnome.org/show_bug.cgi?id=544172
- *
- * Returns: result or %NULL.
- */
-typedef char const * (*bug_544172) (char const *self);
-
-
 /**
  * bug_554833:
  * @i: value;
diff --git a/tests/scan.py b/tests/scan.py
index 97001c3..4691df4 100644
--- a/tests/scan.py
+++ b/tests/scan.py
@@ -373,6 +373,24 @@ class ScanHeaderContentUserFunction(ScanHeaderContentTestCase):
         slist, doc_comments = self.scanHeaderContent([header])
         self.assertDecl('func', 'void', '', slist)
 
+    @parameterized.expand([(t.replace(' ', '_'), t) for t in BASIC_TYPES_WITH_VOID])
+    def test_HandlesReturnValue(self, _, ret_type):
+        header = 'typedef %s (*func)(void);' % ret_type
+        slist, doc_comments = self.scanHeaderContent([header])
+        self.assertDecl('func', ret_type, 'void', slist)
+
+    @parameterized.expand([(t.replace(' ', '_'), t) for t in BASIC_TYPES_WITH_VOID])
+    def test_HandlesReturnValuePtr(self, _, ret_type):
+        header = 'typedef %s* (*func)(void);' % ret_type
+        slist, doc_comments = self.scanHeaderContent([header])
+        self.assertDecl('func', ret_type + ' *', 'void', slist)
+
+    @parameterized.expand([(t.replace(' ', '_'), t) for t in BASIC_TYPES_WITH_VOID])
+    def test_HandlesReturnValueConstPtr(self, _, ret_type):
+        header = 'typedef const %s* (*func)(void);' % ret_type
+        slist, doc_comments = self.scanHeaderContent([header])
+        self.assertDecl('func', 'const ' + ret_type + ' *', 'void', slist)
+
 
 class ScanHeaderContentVariabless(ScanHeaderContentTestCase):
     """Test parsing of variable declarations."""
@@ -418,4 +436,4 @@ if __name__ == '__main__':
     #
     # t = ScanHeaderContentUserFunction()
     # t.setUp()
-    # t.test_FindsFunctionVoid()
+    # t.debug()


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