diff options
Diffstat (limited to 'tests/test_inherit.py')
-rw-r--r-- | tests/test_inherit.py | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/tests/test_inherit.py b/tests/test_inherit.py index 5da57dd9..03527724 100644 --- a/tests/test_inherit.py +++ b/tests/test_inherit.py @@ -3,41 +3,14 @@ Tests for inheritance in RegexLexer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -import unittest - from pygments.lexer import RegexLexer, inherit from pygments.token import Text -class InheritTest(unittest.TestCase): - def test_single_inheritance_position(self): - t = Two() - pats = [x[0].__self__.pattern for x in t._tokens['root']] - self.assertEqual(['x', 'a', 'b', 'y'], pats) - def test_multi_inheritance_beginning(self): - t = Beginning() - pats = [x[0].__self__.pattern for x in t._tokens['root']] - self.assertEqual(['x', 'a', 'b', 'y', 'm'], pats) - def test_multi_inheritance_end(self): - t = End() - pats = [x[0].__self__.pattern for x in t._tokens['root']] - self.assertEqual(['m', 'x', 'a', 'b', 'y'], pats) - - def test_multi_inheritance_position(self): - t = Three() - pats = [x[0].__self__.pattern for x in t._tokens['root']] - self.assertEqual(['i', 'x', 'a', 'b', 'y', 'j'], pats) - - def test_single_inheritance_with_skip(self): - t = Skipped() - pats = [x[0].__self__.pattern for x in t._tokens['root']] - self.assertEqual(['x', 'a', 'b', 'y'], pats) - - class One(RegexLexer): tokens = { 'root': [ @@ -46,6 +19,7 @@ class One(RegexLexer): ], } + class Two(One): tokens = { 'root': [ @@ -55,6 +29,7 @@ class Two(One): ], } + class Three(Two): tokens = { 'root': [ @@ -64,6 +39,7 @@ class Three(Two): ], } + class Beginning(Two): tokens = { 'root': [ @@ -72,6 +48,7 @@ class Beginning(Two): ], } + class End(Two): tokens = { 'root': [ @@ -80,9 +57,11 @@ class End(Two): ], } + class Empty(One): tokens = {} + class Skipped(Empty): tokens = { 'root': [ @@ -92,3 +71,32 @@ class Skipped(Empty): ], } + +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 |