[gi-docgen/link-test] tests: Add a unit for LinkGenerator
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gi-docgen/link-test] tests: Add a unit for LinkGenerator
- Date: Sat, 18 Dec 2021 19:08:18 +0000 (UTC)
commit 9c1e246a18ab22e2468e29da2371b367176f9e91
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sat Dec 18 19:07:18 2021 +0000
tests: Add a unit for LinkGenerator
We need to test both the link regular expression, to ensure it matches
both the plain links and the link with additional text; and the
LinkGenerator class.
test/test_utils.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)
---
diff --git a/test/test_utils.py b/test/test_utils.py
index d48e8c4..d8d4e5e 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -2,9 +2,11 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later OR Apache-2.0
+import xml.etree.ElementTree as ET
+import os
import unittest
-from gidocgen import utils
+from gidocgen import gir, utils
class TestProcessLanguage(unittest.TestCase):
@@ -14,3 +16,62 @@ class TestProcessLanguage(unittest.TestCase):
self.assertEqual(utils.process_language('<!-- language="C" -->'), "c")
self.assertEqual(utils.process_language(' <!-- language="xml" -->'), "xml")
self.assertEqual(utils.process_language('<!-- language="plain" -->'), "plain")
+
+
+class TestLinkGenerator(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ paths = []
+ paths.extend([os.path.join(os.getcwd(), "test/gir")])
+ paths.extend(utils.default_search_paths())
+
+ parser = gir.GirParser(search_paths=paths, error=False)
+ parser.parse(os.path.join(os.getcwd(), "test/gir", "GObject-2.0.gir"))
+
+ cls._repository = parser.get_repository()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls._repository = None
+
+ def test_link_re(self):
+ text = "Some text [type@GObject.Value] other text"
+ res = utils.LINK_RE.search(text)
+ self.assertIsNotNone(res)
+
+ fragment = res.group('fragment')
+ self.assertTrue(fragment == 'type')
+
+ endpoint = res.group('endpoint')
+ self.assertTrue(endpoint == 'GObject.Value')
+
+ alt_text = res.group('text')
+ self.assertIsNone(alt_text)
+
+ text = "Some text [with some text][type@GObject.Binding] other text"
+ res = utils.LINK_RE.search(text)
+ self.assertIsNotNone(res)
+
+ alt_text = res.group('text')
+ self.assertTrue(alt_text == '[with some text]')
+
+ def test_link_generator(self):
+ text = "Some text [with some, amazing, text][type@GObject.Binding] other text"
+ res = utils.LINK_RE.search(text)
+ self.assertIsNotNone(res)
+
+ fragment = res.group('fragment')
+ endpoint = res.group('endpoint')
+ alt_text = res.group('text')
+
+ link = utils.LinkGenerator(line=text, start=res.start(), end=res.end(),
+ namespace=self._repository.namespace,
+ fragment=fragment, endpoint=endpoint, text=alt_text)
+ self.assertIsNotNone(link)
+
+ root = ET.fromstring(str(link))
+ self.assertTrue(root.tag == 'a')
+ self.assertTrue('href' in root.attrib)
+ self.assertTrue(root.attrib['href'] == 'class.Binding.html')
+ self.assertTrue(root.text == 'with some, amazing, text')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]