diff tests/test_algpseudo.py @ 288:298841bc4dee

Allow "normal" Pygments token names in "\ttX" ("Error", "Text.Whitespace", ...)
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 22 May 2026 12:32:38 +0200
parents 051c8877ee22
children 6fc7f9c1d89d
line wrap: on
line diff
--- a/tests/test_algpseudo.py	Fri May 22 12:31:09 2026 +0200
+++ b/tests/test_algpseudo.py	Fri May 22 12:32:38 2026 +0200
@@ -13,6 +13,8 @@
 import pygments.formatters
 from pygments.token import Token
 
+from pygments_lexer_pseudocode2.utils import string_to_defined_tokentype
+
 import _testhelper
 
 
@@ -1243,5 +1245,40 @@
         self.assertTrue(highlighted.startswith(r"""\begin{Verbatim}"""))
 
 
+class TokenBehaviour(unittest.TestCase):
+
+    def test_string_to_defined_tokentype(self):
+        t = string_to_defined_tokentype("Generic")
+        self.assertIs(t, Token.Generic)
+
+    def test_string_to_defined_tokentype_2(self):
+        t = string_to_defined_tokentype("Generic.Error")
+        self.assertIs(t, Token.Generic.Error)
+
+    def test_string_to_defined_tokentype_empty(self):
+        t = string_to_defined_tokentype("")
+        self.assertIs(t, Token)
+
+    def test_string_to_undefined_tokentype(self):
+        self.assertIsNone(string_to_defined_tokentype("non-existing"))
+        # twice to assert that it it not created by the call
+        self.assertIsNone(string_to_defined_tokentype("non-existing"))
+
+    def test_string_to_undefined_tokentype_2(self):
+        self.assertIsNone(string_to_defined_tokentype("Generic.non-existing"))
+        # twice to assert that it it not created by the call
+        self.assertIsNone(string_to_defined_tokentype("Generic.non-existing"))
+
+    def test_string_to_undefined_tokentype_3(self):
+        self.assertIsNone(string_to_defined_tokentype("Not.Yet.Existing"))
+        # twice to assert that it it not created by the call
+        self.assertIsNone(string_to_defined_tokentype("Not.Yet.Existing"))
+
+    def test_string_to_undefined_tokentype_4(self):
+        self.assertIsNone(string_to_defined_tokentype("Generic..Error"))
+        # twice to assert that it it not created by the call
+        self.assertIsNone(string_to_defined_tokentype("Generic..Error"))
+
+
 if __name__ == "__main__":
     unittest.main()