diff tests/test_algpseudo.py @ 286:051c8877ee22

Implement lexer option "strict_tokentype". It allows the \ttX command to synthesize not yet existing token types.
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 21 May 2026 09:32:35 +0200
parents afbca50b7dc1
children 298841bc4dee
line wrap: on
line diff
--- a/tests/test_algpseudo.py	Wed May 20 20:35:37 2026 +0200
+++ b/tests/test_algpseudo.py	Thu May 21 09:32:35 2026 +0200
@@ -11,6 +11,7 @@
 import pygments
 import pygments.lexers
 import pygments.formatters
+from pygments.token import Token
 
 import _testhelper
 
@@ -18,6 +19,7 @@
 class TestSnippets(unittest.TestCase, _testhelper.TokenAssertHelper):
 
     def setUp(self):
+        # The standard lexer
         self.lexer = pygments.lexers.load_lexer_from_file(
             ALGLEXERFILENAME, ALGLEXERCLASS)
 
@@ -794,7 +796,7 @@
             pygments.lex(
                 """\\ttX{nv}{simple\\part 2}""", self.lexer))
 
-    def test_extended_explicit_tokentype_non_existing_type(self):
+    def test_extended_explicit_tokentype_non_existing_type_strict(self):
         self.assertTokenStreamEqualComplete(
             [("Generic.Error", u"\\ttX{NON_EXISTING}{"),
              ("Generic.Error", u"∈_∌"),
@@ -810,6 +812,23 @@
             pygments.lex(
                 u"\\ttX{NON_EXISTING}{∈_∌}(p1, p2)", self.lexer))
 
+    def test_extended_explicit_tokentype_non_existing_type_lenient(self):
+        lexer = pygments.lexers.load_lexer_from_file(
+            ALGLEXERFILENAME, ALGLEXERCLASS, strict_tokentype=False)
+        self.assertTokenStreamEqualComplete(
+            [(getattr(getattr(getattr(Token, "DOES"), "IT"), "NOT-EXIST"),
+              u"∈_∌"),
+             ("Punctuation", "("),
+             ("Name.Entity", "p1"),
+             ("Punctuation", ","),
+             ("Text", " "),
+             ("Name.Entity", "p2"),
+             ("Punctuation", ")"),
+             ("Text.Whitespace", "\n"),
+             ],
+            pygments.lex(
+                u"\\ttX{DOES.IT.NOT-EXIST}{∈_∌}(p1, p2)", lexer))
+
     def test_just_braces_in_expressions(self):
         self.assertTokenStreamEqualComplete(
             [("Punctuation", "{"),