comparison 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
comparison
equal deleted inserted replaced
86:0c05dc09c9e2 87:d8ca835c74ea
4 # SPDX-License-Identifier: MIT 4 # SPDX-License-Identifier: MIT
5 # :- 5 # :-
6 6
7 from _tsetup import ALGLEXERFILENAME, ALGLEXERCLASS 7 from _tsetup import ALGLEXERFILENAME, ALGLEXERCLASS
8 8
9 import sys
9 import unittest 10 import unittest
10 11
11 import pygments 12 import pygments
12 import pygments.lexers 13 import pygments.lexers
13 import pygments.formatters 14 import pygments.formatters
521 ("Operator", "/"), 522 ("Operator", "/"),
522 ("Text", " \n"), # because of r"\s+", Text for expressions 523 ("Text", " \n"), # because of r"\s+", Text for expressions
523 ], 524 ],
524 pygments.lex("\\tt-o/\n\\tt-o// ", self.lexer)) 525 pygments.lex("\\tt-o/\n\\tt-o// ", self.lexer))
525 526
527 @unittest.skipIf(sys.version_info[0] <= 2, "Unicode issue on Python 2")
528 def test_explicit_tokentype_with_remark(self):
529 self.assertTokenStreamEqualComplete(
530 [("Operator", "∈ ∌"),
531 ("Text", " "),
532 ("Comment.Single", "▷"),
533 ("Comment.Single", " ∈ ∌ as (ordinary) operators"),
534 ("Text.Whitespace", "\n"),
535 ],
536 pygments.lex(
537 r"""\ttx-o<∈ ∌> \rem ∈ ∌ as (ordinary) operators""",
538 self.lexer))
539
540 def test_explicit_tokentype_with_remark_2(self):
541 self.assertTokenStreamEqualComplete(
542 [("Operator", "new_operator"),
543 ("Text", " "),
544 ("Comment.Single", "▷"),
545 ("Comment.Single", " a (synthesized) operator"),
546 ("Text.Whitespace", "\n"),
547 ],
548 pygments.lex(
549 r"""\ttx-o<new_operator> \rem a (synthesized) operator""",
550 self.lexer))
551
552 @unittest.skipIf(sys.version_info[0] <= 2, "Unicode issue on Python 2")
553 def test_explicit_tokentype_with_possibly_conflicting_parens(self):
554 self.assertTokenStreamEqualComplete(
555 [("Name.Function", "∈_∌"),
556 ("Punctuation", "("),
557 ("Name.Entity", "p1"),
558 ("Punctuation", ","),
559 ("Text", " "),
560 ("Name.Entity", "p2"),
561 ("Punctuation", ")"),
562 ("Text.Whitespace", "\n"),
563 ],
564 pygments.lex(
565 r"""\ttx-nf<∈_∌>(p1, p2)""",
566 self.lexer))
567
568 def test_explicit_tokentype_with_possibly_conflicting_parens_2(self):
569 self.assertTokenStreamEqualComplete(
570 [("Name.Decorator", "a_Decorator"),
571 ("Punctuation", "("),
572 ("Name.Entity", "p1"),
573 ("Punctuation", ","),
574 ("Text", " "),
575 ("Name.Entity", "p2"),
576 ("Punctuation", ")"),
577 ("Text", " "),
578 ("Comment.Single", "▷"),
579 ("Comment.Single", " (Python) decorator"),
580 ("Text.Whitespace", "\n"),
581 ],
582 pygments.lex(
583 r"""\ttx-nd<a_Decorator>(p1, p2) \rem (Python) decorator""",
584 self.lexer))
585
586 def test_explicit_tokentype_with_possibly_conflicting_parens_3(self):
587 self.assertTokenStreamEqualComplete(
588 [("Name.Decorator", "a_Decorator"),
589 ("Punctuation", "("),
590 ("Name.Entity", "p1"),
591 ("Punctuation", ","),
592 ("Text", " "),
593 ("Name.Entity", "p2"),
594 ("Punctuation", ")"),
595 ("Text", " "),
596 ("Comment.Single", "▷"),
597 ("Comment.Single", " (Python) annotation"),
598 ("Text.Whitespace", "\n"),
599 ],
600 pygments.lex(
601 r"""\ttx-nd[a_Decorator](p1, p2) \rem (Python) annotation""",
602 self.lexer))
603
604 def test_explicit_tokentype_error(self):
605 self.assertTokenStreamEqualComplete(
606 [("Generic.Error", r"""\ttx-non-existing[a_Decorator]"""),
607 ("Text.Whitespace", "\n"),
608 ],
609 pygments.lex(
610 r"""\ttx-non-existing[a_Decorator]""",
611 self.lexer))
612
526 613
527 class PygmentizeCompletely(unittest.TestCase): 614 class PygmentizeCompletely(unittest.TestCase):
528 615
529 def setUp(self): 616 def setUp(self):
530 self.lexer = pygments.lexers.load_lexer_from_file( 617 self.lexer = pygments.lexers.load_lexer_from_file(