Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
diff tests/test_algpseudo.py @ 87:d8ca835c74ea
FIX: Erroneous parsing of \tt-XXX and \ttx-XXX:
Need to restrict the tokentype group because otherwise it would match
too much if some sort of braces are mixed on a single line.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 02 May 2026 10:07:59 +0200 |
| parents | 3ac1c4502ad0 |
| children | 3f37832c405d |
line wrap: on
line diff
--- a/tests/test_algpseudo.py Sat May 02 09:54:03 2026 +0200 +++ b/tests/test_algpseudo.py Sat May 02 10:07:59 2026 +0200 @@ -6,6 +6,7 @@ from _tsetup import ALGLEXERFILENAME, ALGLEXERCLASS +import sys import unittest import pygments @@ -523,6 +524,92 @@ ], pygments.lex("\\tt-o/\n\\tt-o// ", self.lexer)) + @unittest.skipIf(sys.version_info[0] <= 2, "Unicode issue on Python 2") + def test_explicit_tokentype_with_remark(self): + self.assertTokenStreamEqualComplete( + [("Operator", "∈ ∌"), + ("Text", " "), + ("Comment.Single", "▷"), + ("Comment.Single", " ∈ ∌ as (ordinary) operators"), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\ttx-o<∈ ∌> \rem ∈ ∌ as (ordinary) operators""", + self.lexer)) + + def test_explicit_tokentype_with_remark_2(self): + self.assertTokenStreamEqualComplete( + [("Operator", "new_operator"), + ("Text", " "), + ("Comment.Single", "▷"), + ("Comment.Single", " a (synthesized) operator"), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\ttx-o<new_operator> \rem a (synthesized) operator""", + self.lexer)) + + @unittest.skipIf(sys.version_info[0] <= 2, "Unicode issue on Python 2") + def test_explicit_tokentype_with_possibly_conflicting_parens(self): + self.assertTokenStreamEqualComplete( + [("Name.Function", "∈_∌"), + ("Punctuation", "("), + ("Name.Entity", "p1"), + ("Punctuation", ","), + ("Text", " "), + ("Name.Entity", "p2"), + ("Punctuation", ")"), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\ttx-nf<∈_∌>(p1, p2)""", + self.lexer)) + + def test_explicit_tokentype_with_possibly_conflicting_parens_2(self): + self.assertTokenStreamEqualComplete( + [("Name.Decorator", "a_Decorator"), + ("Punctuation", "("), + ("Name.Entity", "p1"), + ("Punctuation", ","), + ("Text", " "), + ("Name.Entity", "p2"), + ("Punctuation", ")"), + ("Text", " "), + ("Comment.Single", "▷"), + ("Comment.Single", " (Python) decorator"), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\ttx-nd<a_Decorator>(p1, p2) \rem (Python) decorator""", + self.lexer)) + + def test_explicit_tokentype_with_possibly_conflicting_parens_3(self): + self.assertTokenStreamEqualComplete( + [("Name.Decorator", "a_Decorator"), + ("Punctuation", "("), + ("Name.Entity", "p1"), + ("Punctuation", ","), + ("Text", " "), + ("Name.Entity", "p2"), + ("Punctuation", ")"), + ("Text", " "), + ("Comment.Single", "▷"), + ("Comment.Single", " (Python) annotation"), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\ttx-nd[a_Decorator](p1, p2) \rem (Python) annotation""", + self.lexer)) + + def test_explicit_tokentype_error(self): + self.assertTokenStreamEqualComplete( + [("Generic.Error", r"""\ttx-non-existing[a_Decorator]"""), + ("Text.Whitespace", "\n"), + ], + pygments.lex( + r"""\ttx-non-existing[a_Decorator]""", + self.lexer)) + class PygmentizeCompletely(unittest.TestCase):
