diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 11:33:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 11:33:32 +0000 |
commit | 1f403ad2197fc7442409f434ee574f3e6b46fb73 (patch) | |
tree | 0299c6dd11d5edfa918a29b6456bc1875f1d288c /tests/test_inherit.py | |
parent | Initial commit. (diff) | |
download | pygments-1f403ad2197fc7442409f434ee574f3e6b46fb73.tar.xz pygments-1f403ad2197fc7442409f434ee574f3e6b46fb73.zip |
Adding upstream version 2.14.0+dfsg.upstream/2.14.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_inherit.py')
-rw-r--r-- | tests/test_inherit.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/test_inherit.py b/tests/test_inherit.py new file mode 100644 index 0000000..a276378 --- /dev/null +++ b/tests/test_inherit.py @@ -0,0 +1,101 @@ +""" + Tests for inheritance in RegexLexer + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, inherit +from pygments.token import Text + + +class One(RegexLexer): + tokens = { + 'root': [ + ('a', Text), + ('b', Text), + ], + } + + +class Two(One): + tokens = { + 'root': [ + ('x', Text), + inherit, + ('y', Text), + ], + } + + +class Three(Two): + tokens = { + 'root': [ + ('i', Text), + inherit, + ('j', Text), + ], + } + + +class Beginning(Two): + tokens = { + 'root': [ + inherit, + ('m', Text), + ], + } + + +class End(Two): + tokens = { + 'root': [ + ('m', Text), + inherit, + ], + } + + +class Empty(One): + tokens = {} + + +class Skipped(Empty): + tokens = { + 'root': [ + ('x', Text), + inherit, + ('y', Text), + ], + } + + +def test_single_inheritance_position(): + t = Two() + pats = [x[0].__self__.pattern for x in t._tokens['root']] + assert ['x', 'a', 'b', 'y'] == pats + + +def test_multi_inheritance_beginning(): + t = Beginning() + pats = [x[0].__self__.pattern for x in t._tokens['root']] + assert ['x', 'a', 'b', 'y', 'm'] == pats + + +def test_multi_inheritance_end(): + t = End() + pats = [x[0].__self__.pattern for x in t._tokens['root']] + assert ['m', 'x', 'a', 'b', 'y'] == pats + + +def test_multi_inheritance_position(): + t = Three() + pats = [x[0].__self__.pattern for x in t._tokens['root']] + assert ['i', 'x', 'a', 'b', 'y', 'j'] == pats + + +def test_single_inheritance_with_skip(): + t = Skipped() + pats = [x[0].__self__.pattern for x in t._tokens['root']] + assert ['x', 'a', 'b', 'y'] == pats |