[gtk-doc] common: port the tests as well and fix one bug



commit 4abd4e419a07939e89100c90540e9ce025109048
Author: Stefan Sauer <ensonic users sf net>
Date:   Thu Apr 13 21:23:51 2017 +0200

    common: port the tests as well and fix one bug

 gtkdoc/common.py       |    2 +-
 tests/gtkdoc-common.py |   21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/gtkdoc/common.py b/gtkdoc/common.py
index ef61574..a2d0e60 100644
--- a/gtkdoc/common.py
+++ b/gtkdoc/common.py
@@ -113,7 +113,7 @@ def CreateValidSGMLID(id):
     if id is "_":
         return "gettext-macro"
 
-    id = id.strip(',;')
+    id = re.sub(r'[,;]', '', id)
     id = re.sub(r'[_ ]', '-', id)
     id = re.sub(r'^-+', '', id)
     id = id.replace('::', '-')
diff --git a/tests/gtkdoc-common.py b/tests/gtkdoc-common.py
index 722ae5a..ee3a1ac 100755
--- a/tests/gtkdoc-common.py
+++ b/tests/gtkdoc-common.py
@@ -1,18 +1,33 @@
 #!/usr/bin/env python
 
-import mock, os, unittest
+import mock
+import unittest
 
 from gtkdoc import common
 
-class TestCommon(unittest.TestCase):
+
+class TestUpdateFileIfChanged(unittest.TestCase):
 
     @mock.patch('os.path.exists')
     @mock.patch('os.rename')
-    def test_UpdateFileIfChanged_NoOldFile(self, os_rename, os_path_exists):
+    def test_NoOldFile(self, os_rename, os_path_exists):
         os_path_exists.return_value = False
         res = common.UpdateFileIfChanged('/foo', '/bar', False)
         os_rename.assert_called_with('/bar', '/foo')
         self.assertTrue(res)
 
+
+class TestCreateValidSGMLID(unittest.TestCase):
+
+    def test_AlreadyValid(self):
+        self.assertEquals(common.CreateValidSGMLID('x'), 'x')
+
+    def test_SpecialCharsBecomeDash(self):
+        self.assertEquals(common.CreateValidSGMLID('x_ y'), 'x--y')
+
+    def test_SpecialCharsGetRemoved(self):
+        self.assertEquals(common.CreateValidSGMLID('x,;y'), 'xy')
+
+
 if __name__ == '__main__':
     unittest.main()


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