From 6ded9db39463372e5205a36bea72d6de516ece69 Mon Sep 17 00:00:00 2001 From: Christian Hammond Date: Fri, 4 Nov 2016 16:57:38 -0700 Subject: 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. --- tests/test_python.py | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/test_python.py (limited to 'tests/test_python.py') diff --git a/tests/test_python.py b/tests/test_python.py new file mode 100644 index 00000000..f5784cb1 --- /dev/null +++ b/tests/test_python.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +""" + Python Tests + ~~~~~~~~~~~~ + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest + +from pygments.lexers import PythonLexer, Python3Lexer +from pygments.token import Token + + +class PythonTest(unittest.TestCase): + def setUp(self): + self.lexer = PythonLexer() + + def test_cls_builtin(self): + """ + Tests that a cls token gets interpreted as a Token.Name.Builtin.Pseudo + + """ + fragment = 'class TestClass():\n @classmethod\n def hello(cls):\n pass\n' + tokens = [ + (Token.Keyword, 'class'), + (Token.Text, ' '), + (Token.Name.Class, 'TestClass'), + (Token.Punctuation, '('), + (Token.Punctuation, ')'), + (Token.Punctuation, ':'), + (Token.Text, '\n'), + (Token.Text, ' '), + (Token.Name.Decorator, '@classmethod'), + (Token.Text, '\n'), + (Token.Text, ' '), + (Token.Keyword, 'def'), + (Token.Text, ' '), + (Token.Name.Function, 'hello'), + (Token.Punctuation, '('), + (Token.Name.Builtin.Pseudo, 'cls'), + (Token.Punctuation, ')'), + (Token.Punctuation, ':'), + (Token.Text, '\n'), + (Token.Text, ' '), + (Token.Keyword, 'pass'), + (Token.Text, '\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + +class Python3Test(unittest.TestCase): + def setUp(self): + self.lexer = Python3Lexer() + + def testNeedsName(self): + """ + Tests that '@' is recognized as an Operator + """ + fragment = u'S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)\n' + tokens = [ + (Token.Name, u'S'), + (Token.Text, u' '), + (Token.Operator, u'='), + (Token.Text, u' '), + (Token.Punctuation, u'('), + (Token.Name, u'H'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Text, u' '), + (Token.Name, u'beta'), + (Token.Text, u' '), + (Token.Operator, u'-'), + (Token.Text, u' '), + (Token.Name, u'r'), + (Token.Punctuation, u')'), + (Token.Operator, u'.'), + (Token.Name, u'T'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Text, u' '), + (Token.Name, u'inv'), + (Token.Punctuation, u'('), + (Token.Name, u'H'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Text, u' '), + (Token.Name, u'V'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Text, u' '), + (Token.Name, u'H'), + (Token.Operator, u'.'), + (Token.Name, u'T'), + (Token.Punctuation, u')'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Text, u' '), + (Token.Punctuation, u'('), + (Token.Name, u'H'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Text, u' '), + (Token.Name, u'beta'), + (Token.Text, u' '), + (Token.Operator, u'-'), + (Token.Text, u' '), + (Token.Name, u'r'), + (Token.Punctuation, u')'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) -- cgit v1.2.1 From 00126a1401eefcf0280384d9bf59783e81db41ed Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 22 Jan 2017 18:38:11 +0100 Subject: Copyright update. --- tests/test_python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_python.py') diff --git a/tests/test_python.py b/tests/test_python.py index f5784cb1..e99687a6 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -3,7 +3,7 @@ Python Tests ~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -- cgit v1.2.1