summaryrefslogtreecommitdiff
path: root/tests/test_inherit.py
diff options
context:
space:
mode:
authorChristian Hammond <christian@beanbaginc.com>2016-11-04 16:57:38 -0700
committerChristian Hammond <christian@beanbaginc.com>2016-11-04 16:57:38 -0700
commit6ded9db39463372e5205a36bea72d6de516ece69 (patch)
tree1d1f497cc99dd44d2ee7e2c3daa35965157ff924 /tests/test_inherit.py
downloadpygments-git-6ded9db39463372e5205a36bea72d6de516ece69.tar.gz
Add support for partials and path segments for Handlebars.
This introduces support for some missing features to the Handlebars lexer: Partials and path segments. Partials mostly appeared to work before, but the `>` in `{{> ... }}` would appear as a syntax error, as could other components of the partial. This change introduces support for: * Standard partials: `{{> partialName}}` * Partials with parameters: `{{> partialName varname="value"}}` * Ddynamic partials: `{{> (partialFunc)}}` * Ddynamic partials with lookups: `{{> (lookup ../path "partialName")}}` * Partial blocks: `{{> @partial-block}}` * Inline partials: `{{#*inline}}..{{/inline}}` It also introduces support for path segments, which can reference content in the current context or in a parent context. For instance, `this.name`, `this/name`, `./name`, `../name`, `this/name`, etc. These are all now tracked as variables.
Diffstat (limited to 'tests/test_inherit.py')
-rw-r--r--tests/test_inherit.py94
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..34033a08
--- /dev/null
+++ b/tests/test_inherit.py
@@ -0,0 +1,94 @@
+# -*- coding: utf-8 -*-
+"""
+ Tests for inheritance in RegexLexer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright 2006-2015 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),
+ ],
+ }
+