Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 285:afbca50b7dc1 | 286:051c8877ee22 |
|---|---|
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 import pygments | 11 import pygments |
| 12 import pygments.lexers | 12 import pygments.lexers |
| 13 import pygments.formatters | 13 import pygments.formatters |
| 14 from pygments.token import Token | |
| 14 | 15 |
| 15 import _testhelper | 16 import _testhelper |
| 16 | 17 |
| 17 | 18 |
| 18 class TestSnippets(unittest.TestCase, _testhelper.TokenAssertHelper): | 19 class TestSnippets(unittest.TestCase, _testhelper.TokenAssertHelper): |
| 19 | 20 |
| 20 def setUp(self): | 21 def setUp(self): |
| 22 # The standard lexer | |
| 21 self.lexer = pygments.lexers.load_lexer_from_file( | 23 self.lexer = pygments.lexers.load_lexer_from_file( |
| 22 ALGLEXERFILENAME, ALGLEXERCLASS) | 24 ALGLEXERFILENAME, ALGLEXERCLASS) |
| 23 | 25 |
| 24 def test_lf(self): | 26 def test_lf(self): |
| 25 self.assertTokenStreamEqualComplete( | 27 self.assertTokenStreamEqualComplete( |
| 792 ("Text.Whitespace", "\n"), | 794 ("Text.Whitespace", "\n"), |
| 793 ], | 795 ], |
| 794 pygments.lex( | 796 pygments.lex( |
| 795 """\\ttX{nv}{simple\\part 2}""", self.lexer)) | 797 """\\ttX{nv}{simple\\part 2}""", self.lexer)) |
| 796 | 798 |
| 797 def test_extended_explicit_tokentype_non_existing_type(self): | 799 def test_extended_explicit_tokentype_non_existing_type_strict(self): |
| 798 self.assertTokenStreamEqualComplete( | 800 self.assertTokenStreamEqualComplete( |
| 799 [("Generic.Error", u"\\ttX{NON_EXISTING}{"), | 801 [("Generic.Error", u"\\ttX{NON_EXISTING}{"), |
| 800 ("Generic.Error", u"∈_∌"), | 802 ("Generic.Error", u"∈_∌"), |
| 801 ("Generic.Error", u"}"), | 803 ("Generic.Error", u"}"), |
| 802 ("Punctuation", "("), | 804 ("Punctuation", "("), |
| 807 ("Punctuation", ")"), | 809 ("Punctuation", ")"), |
| 808 ("Text.Whitespace", "\n"), | 810 ("Text.Whitespace", "\n"), |
| 809 ], | 811 ], |
| 810 pygments.lex( | 812 pygments.lex( |
| 811 u"\\ttX{NON_EXISTING}{∈_∌}(p1, p2)", self.lexer)) | 813 u"\\ttX{NON_EXISTING}{∈_∌}(p1, p2)", self.lexer)) |
| 814 | |
| 815 def test_extended_explicit_tokentype_non_existing_type_lenient(self): | |
| 816 lexer = pygments.lexers.load_lexer_from_file( | |
| 817 ALGLEXERFILENAME, ALGLEXERCLASS, strict_tokentype=False) | |
| 818 self.assertTokenStreamEqualComplete( | |
| 819 [(getattr(getattr(getattr(Token, "DOES"), "IT"), "NOT-EXIST"), | |
| 820 u"∈_∌"), | |
| 821 ("Punctuation", "("), | |
| 822 ("Name.Entity", "p1"), | |
| 823 ("Punctuation", ","), | |
| 824 ("Text", " "), | |
| 825 ("Name.Entity", "p2"), | |
| 826 ("Punctuation", ")"), | |
| 827 ("Text.Whitespace", "\n"), | |
| 828 ], | |
| 829 pygments.lex( | |
| 830 u"\\ttX{DOES.IT.NOT-EXIST}{∈_∌}(p1, p2)", lexer)) | |
| 812 | 831 |
| 813 def test_just_braces_in_expressions(self): | 832 def test_just_braces_in_expressions(self): |
| 814 self.assertTokenStreamEqualComplete( | 833 self.assertTokenStreamEqualComplete( |
| 815 [("Punctuation", "{"), | 834 [("Punctuation", "{"), |
| 816 ("Name.Entity", "foo"), | 835 ("Name.Entity", "foo"), |
