diff options
author | Tim Hatch <tim@timhatch.com> | 2014-10-28 15:00:00 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2014-10-28 15:00:00 -0700 |
commit | aad6a1e0d9aadf6393216855560fa3bb2102b01b (patch) | |
tree | aaad53a4c66fe9a4fba325a81126a405d9e86ea8 /tests/test_inherit.py | |
parent | 20ee43aff8281fa94609d2ec33cd0cf852599700 (diff) | |
download | pygments-aad6a1e0d9aadf6393216855560fa3bb2102b01b.tar.gz |
Add test for RegexLexer inheritance (fails with current code).
Diffstat (limited to 'tests/test_inherit.py')
-rw-r--r-- | tests/test_inherit.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/test_inherit.py b/tests/test_inherit.py new file mode 100644 index 00000000..0bccb91a --- /dev/null +++ b/tests/test_inherit.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +""" + Tests for inheritance in RegexLexer + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2014 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': [ + ('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), + ], + } + |