Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison tests/test_algpseudo.py @ 289:6fc7f9c1d89d
Remove the old implementation of explicit token types completely
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 22 May 2026 12:41:08 +0200 |
| parents | 298841bc4dee |
| children | b09873e4df58 |
comparison
equal
deleted
inserted
replaced
| 288:298841bc4dee | 289:6fc7f9c1d89d |
|---|---|
| 573 ("Text.Whitespace", "\n"), | 573 ("Text.Whitespace", "\n"), |
| 574 ], | 574 ], |
| 575 pygments.lex( | 575 pygments.lex( |
| 576 r"\TEXT{\EXPRESSION{first expression} " | 576 r"\TEXT{\EXPRESSION{first expression} " |
| 577 r"\EXPR{second expression}}", | 577 r"\EXPR{second expression}}", |
| 578 self.lexer)) | |
| 579 | |
| 580 def test_explicit_extended_single_tokentype_1(self): | |
| 581 self.assertTokenStreamEqualComplete( | |
| 582 [("Operator", "%"), | |
| 583 ("Text.Whitespace", "\n"), | |
| 584 ], | |
| 585 pygments.lex(r"\ttx-o:%:", self.lexer)) | |
| 586 | |
| 587 def test_explicit_extended_single_tokentype_2(self): | |
| 588 self.assertTokenStreamEqualComplete( | |
| 589 [("Operator", "{"), | |
| 590 ("Text.Whitespace", "\n"), | |
| 591 ], | |
| 592 pygments.lex(r"\ttx-o{{}", self.lexer)) | |
| 593 | |
| 594 def test_explicit_extended_single_tokentype_3(self): | |
| 595 self.assertTokenStreamEqualComplete( | |
| 596 [("Operator", "<"), | |
| 597 ("Text.Whitespace", "\n"), | |
| 598 ], | |
| 599 pygments.lex(r"\ttx-o<<>", self.lexer)) | |
| 600 | |
| 601 def test_explicit_extended_single_tokentype_4(self): | |
| 602 self.assertTokenStreamEqualComplete( | |
| 603 [("Operator", "("), | |
| 604 ("Text.Whitespace", "\n"), | |
| 605 ], | |
| 606 pygments.lex(r"\ttx-o(()", self.lexer)) | |
| 607 | |
| 608 def test_explicit_extended_multi_tokentype_1(self): | |
| 609 self.assertTokenStreamEqualComplete( | |
| 610 [("Operator", "xxx in A"), | |
| 611 ("Text.Whitespace", "\n"), | |
| 612 ], | |
| 613 pygments.lex(r"\ttx-o/xxx in A/", self.lexer)) | |
| 614 | |
| 615 def test_explicit_extended_multi_tokentype_2(self): | |
| 616 self.assertTokenStreamEqualComplete( | |
| 617 [("Operator", "xxx in B"), | |
| 618 ("Text.Whitespace", "\n"), | |
| 619 ], | |
| 620 pygments.lex(r"\ttx-o{xxx in B}", self.lexer)) | |
| 621 | |
| 622 def test_explicit_extended_multi_tokentype_3(self): | |
| 623 self.assertTokenStreamEqualComplete( | |
| 624 [("Operator", "xxx in C"), | |
| 625 ("Text.Whitespace", "\n"), | |
| 626 ], | |
| 627 pygments.lex(r"\ttx-o<xxx in C>", self.lexer)) | |
| 628 | |
| 629 def test_explicit_extended_multi_tokentype_4(self): | |
| 630 self.assertTokenStreamEqualComplete( | |
| 631 [("Operator", "xxx in D"), | |
| 632 ("Text.Whitespace", "\n"), | |
| 633 ], | |
| 634 pygments.lex(r"\ttx-o(xxx in D)", self.lexer)) | |
| 635 | |
| 636 def test_explicit_tokentype_simple_1(self): | |
| 637 self.assertTokenStreamEqualComplete( | |
| 638 [("Operator", "}"), | |
| 639 ("Operator", "/"), | |
| 640 ("Text.Whitespace", "\n"), | |
| 641 ], | |
| 642 pygments.lex(r"\tt-o/}\tt-o//", self.lexer)) | |
| 643 | |
| 644 def test_explicit_tokentype_simple_2(self): | |
| 645 self.assertTokenStreamEqualComplete( | |
| 646 [("Operator", "\n"), | |
| 647 ("Operator", "/"), | |
| 648 ("Text", " "), | |
| 649 ("Text.Whitespace", "\n"), | |
| 650 ], | |
| 651 pygments.lex("\\tt-o/\n\\tt-o// ", self.lexer)) | |
| 652 | |
| 653 def test_explicit_tokentype_with_remark(self): | |
| 654 self.assertTokenStreamEqualComplete( | |
| 655 [("Operator", u"∈ ∌"), | |
| 656 ("Text", " "), | |
| 657 ("Comment.Single", u"▷"), | |
| 658 ("Comment.Single", u" ∈ ∌ as (ordinary) operators"), | |
| 659 ("Text.Whitespace", "\n"), | |
| 660 ], | |
| 661 pygments.lex( | |
| 662 u"""\\ttx-o<∈ ∌> \\rem ∈ ∌ as (ordinary) operators""", | |
| 663 self.lexer)) | |
| 664 | |
| 665 def test_explicit_tokentype_with_remark_2(self): | |
| 666 self.assertTokenStreamEqualComplete( | |
| 667 [("Operator", "new_operator"), | |
| 668 ("Text", " "), | |
| 669 ("Comment.Single", u"▷"), | |
| 670 ("Comment.Single", " a (synthesized) operator"), | |
| 671 ("Text.Whitespace", "\n"), | |
| 672 ], | |
| 673 pygments.lex( | |
| 674 r"""\ttx-o<new_operator> \rem a (synthesized) operator""", | |
| 675 self.lexer)) | |
| 676 | |
| 677 def test_explicit_tokentype_with_possibly_conflicting_parens(self): | |
| 678 self.assertTokenStreamEqualComplete( | |
| 679 [("Name.Function", u"∈_∌"), | |
| 680 ("Punctuation", "("), | |
| 681 ("Name.Entity", "p1"), | |
| 682 ("Punctuation", ","), | |
| 683 ("Text", " "), | |
| 684 ("Name.Entity", "p2"), | |
| 685 ("Punctuation", ")"), | |
| 686 ("Text.Whitespace", "\n"), | |
| 687 ], | |
| 688 pygments.lex( | |
| 689 u"""\\ttx-nf<∈_∌>(p1, p2)""", | |
| 690 self.lexer)) | |
| 691 | |
| 692 def test_explicit_tokentype_with_possibly_conflicting_parens_2(self): | |
| 693 self.assertTokenStreamEqualComplete( | |
| 694 [("Name.Decorator", "a_Decorator"), | |
| 695 ("Punctuation", "("), | |
| 696 ("Name.Entity", "p1"), | |
| 697 ("Punctuation", ","), | |
| 698 ("Text", " "), | |
| 699 ("Name.Entity", "p2"), | |
| 700 ("Punctuation", ")"), | |
| 701 ("Text", " "), | |
| 702 ("Comment.Single", u"▷"), | |
| 703 ("Comment.Single", " (Python) decorator"), | |
| 704 ("Text.Whitespace", "\n"), | |
| 705 ], | |
| 706 pygments.lex( | |
| 707 r"""\ttx-nd<a_Decorator>(p1, p2) \rem (Python) decorator""", | |
| 708 self.lexer)) | |
| 709 | |
| 710 def test_explicit_tokentype_with_possibly_conflicting_parens_3(self): | |
| 711 self.assertTokenStreamEqualComplete( | |
| 712 [("Name.Decorator", "a_Decorator"), | |
| 713 ("Punctuation", "("), | |
| 714 ("Name.Entity", "p1"), | |
| 715 ("Punctuation", ","), | |
| 716 ("Text", " "), | |
| 717 ("Name.Entity", "p2"), | |
| 718 ("Punctuation", ")"), | |
| 719 ("Text", " "), | |
| 720 ("Comment.Single", u"▷"), | |
| 721 ("Comment.Single", " (Python) annotation"), | |
| 722 ("Text.Whitespace", "\n"), | |
| 723 ], | |
| 724 pygments.lex( | |
| 725 r"""\ttx-nd[a_Decorator](p1, p2) \rem (Python) annotation""", | |
| 726 self.lexer)) | |
| 727 | |
| 728 def test_explicit_tokentype_all_seps(self): | |
| 729 for sep in r"""/?.,:;%|=*+!$"'~_-#@""": | |
| 730 self.assertTokenStreamEqualComplete( | |
| 731 [("Name.Decorator", "word"), | |
| 732 ("Text", sep), | |
| 733 ("Text.Whitespace", "\n"), | |
| 734 ], | |
| 735 pygments.lex( | |
| 736 r"\text{\ttx-nd%sword%s%s}" % (sep, sep, sep), | |
| 737 self.lexer)) | |
| 738 | |
| 739 def test_explicit_tokentype_backslash(self): | |
| 740 self.assertTokenStreamEqualComplete( | |
| 741 [("Name.Decorator", "word"), | |
| 742 ("Text", "\\"), | |
| 743 ("Text", " "), | |
| 744 ("Text.Whitespace", "\n"), | |
| 745 ], | |
| 746 pygments.lex(r"\text{\ttx-nd\word\\ }", self.lexer)) | |
| 747 | |
| 748 def test_explicit_tokentype_error(self): | |
| 749 self.assertTokenStreamEqualComplete( | |
| 750 [("Generic.Error", r"""\ttx-non-existing[a_Decorator]"""), | |
| 751 ("Text.Whitespace", "\n"), | |
| 752 ], | |
| 753 pygments.lex( | |
| 754 r"""\ttx-non-existing[a_Decorator]""", | |
| 755 self.lexer)) | 578 self.lexer)) |
| 756 | 579 |
| 757 def test_extended_explicit_tokentype_empty(self): | 580 def test_extended_explicit_tokentype_empty(self): |
| 758 self.assertTokenStreamEqualComplete( | 581 self.assertTokenStreamEqualComplete( |
| 759 [("Text.Whitespace", "\n")], | 582 [("Text.Whitespace", "\n")], |
