Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison tests/test_algpseudo.py @ 285:afbca50b7dc1
Implement an alternate syntax for "Explicit Token Types".
Uses a generic two-argument syntax and allows escaping of characters using
the common excaping rules.
For this to work the AlgPseudocodeLexer is now based on Pygment's
ExtendedRegexLexer instead of RegexLexer.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 20 May 2026 20:35:37 +0200 |
| parents | ee512932d603 |
| children | 051c8877ee22 |
comparison
equal
deleted
inserted
replaced
| 284:1683a10eabb2 | 285:afbca50b7dc1 |
|---|---|
| 747 ("Text.Whitespace", "\n"), | 747 ("Text.Whitespace", "\n"), |
| 748 ], | 748 ], |
| 749 pygments.lex( | 749 pygments.lex( |
| 750 r"""\ttx-non-existing[a_Decorator]""", | 750 r"""\ttx-non-existing[a_Decorator]""", |
| 751 self.lexer)) | 751 self.lexer)) |
| 752 | |
| 753 def test_extended_explicit_tokentype_empty(self): | |
| 754 self.assertTokenStreamEqualComplete( | |
| 755 [("Text.Whitespace", "\n")], | |
| 756 pygments.lex( | |
| 757 r"""\ttX{nd}{}""", self.lexer)) | |
| 758 | |
| 759 def test_extended_explicit_tokentype_simple(self): | |
| 760 self.assertTokenStreamEqualComplete( | |
| 761 [("Name.Decorator", "simple\nline 2"), | |
| 762 ("Text.Whitespace", "\n"), | |
| 763 ], | |
| 764 pygments.lex( | |
| 765 """\\ttX{nd}{simple\nline 2}""", self.lexer)) | |
| 766 | |
| 767 def test_extended_explicit_tokentype_escaped_brace(self): | |
| 768 self.assertTokenStreamEqualComplete( | |
| 769 [("Name.Decorator", "simple"), | |
| 770 ("Name.Decorator", "}"), | |
| 771 ("Name.Decorator", "part 2"), | |
| 772 ("Text.Whitespace", "\n"), | |
| 773 ], | |
| 774 pygments.lex( | |
| 775 """\\ttX{nd}{simple\\}part 2}""", self.lexer)) | |
| 776 | |
| 777 def test_extended_explicit_tokentype_escaped_backslash(self): | |
| 778 self.assertTokenStreamEqualComplete( | |
| 779 [("Name.Decorator", "simple"), | |
| 780 ("Name.Decorator", "\\"), | |
| 781 ("Name.Decorator", "part 2"), | |
| 782 ("Text.Whitespace", "\n"), | |
| 783 ], | |
| 784 pygments.lex( | |
| 785 """\\ttX{nd}{simple\\\\part 2}""", self.lexer)) | |
| 786 | |
| 787 def test_extended_explicit_tokentype_single_backslash(self): | |
| 788 self.assertTokenStreamEqualComplete( | |
| 789 [("Name.Variable", "simple"), | |
| 790 ("Generic.Error", "\\"), | |
| 791 ("Name.Variable", "part 2"), | |
| 792 ("Text.Whitespace", "\n"), | |
| 793 ], | |
| 794 pygments.lex( | |
| 795 """\\ttX{nv}{simple\\part 2}""", self.lexer)) | |
| 796 | |
| 797 def test_extended_explicit_tokentype_non_existing_type(self): | |
| 798 self.assertTokenStreamEqualComplete( | |
| 799 [("Generic.Error", u"\\ttX{NON_EXISTING}{"), | |
| 800 ("Generic.Error", u"∈_∌"), | |
| 801 ("Generic.Error", u"}"), | |
| 802 ("Punctuation", "("), | |
| 803 ("Name.Entity", "p1"), | |
| 804 ("Punctuation", ","), | |
| 805 ("Text", " "), | |
| 806 ("Name.Entity", "p2"), | |
| 807 ("Punctuation", ")"), | |
| 808 ("Text.Whitespace", "\n"), | |
| 809 ], | |
| 810 pygments.lex( | |
| 811 u"\\ttX{NON_EXISTING}{∈_∌}(p1, p2)", self.lexer)) | |
| 812 | |
| 813 def test_just_braces_in_expressions(self): | |
| 814 self.assertTokenStreamEqualComplete( | |
| 815 [("Punctuation", "{"), | |
| 816 ("Name.Entity", "foo"), | |
| 817 ("Text", " "), | |
| 818 ("Name.Entity", "bar"), | |
| 819 ("Punctuation", "}"), | |
| 820 ("Text.Whitespace", "\n"), | |
| 821 ], | |
| 822 pygments.lex( | |
| 823 r"{foo bar}", self.lexer)) | |
| 752 | 824 |
| 753 def test_end_combinations(self): | 825 def test_end_combinations(self): |
| 754 self.assertTokenStreamEqualComplete( | 826 self.assertTokenStreamEqualComplete( |
| 755 [("Keyword", "BEGIN"), | 827 [("Keyword", "BEGIN"), |
| 756 ("Text", " "), | 828 ("Text", " "), |
