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_shell.py | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 tests/test_shell.py (limited to 'tests/test_shell.py') diff --git a/tests/test_shell.py b/tests/test_shell.py new file mode 100644 index 00000000..6faac9fd --- /dev/null +++ b/tests/test_shell.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- +""" + Basic Shell Tests + ~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest + +from pygments.token import Token +from pygments.lexers import BashLexer, BashSessionLexer + + +class BashTest(unittest.TestCase): + + def setUp(self): + self.lexer = BashLexer() + self.maxDiff = None + + def testCurlyNoEscapeAndQuotes(self): + fragment = u'echo "${a//["b"]/}"\n' + tokens = [ + (Token.Name.Builtin, u'echo'), + (Token.Text, u' '), + (Token.Literal.String.Double, u'"'), + (Token.String.Interpol, u'${'), + (Token.Name.Variable, u'a'), + (Token.Punctuation, u'//['), + (Token.Literal.String.Double, u'"b"'), + (Token.Punctuation, u']/'), + (Token.String.Interpol, u'}'), + (Token.Literal.String.Double, u'"'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testCurlyWithEscape(self): + fragment = u'echo ${a//[\\"]/}\n' + tokens = [ + (Token.Name.Builtin, u'echo'), + (Token.Text, u' '), + (Token.String.Interpol, u'${'), + (Token.Name.Variable, u'a'), + (Token.Punctuation, u'//['), + (Token.Literal.String.Escape, u'\\"'), + (Token.Punctuation, u']/'), + (Token.String.Interpol, u'}'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testParsedSingle(self): + fragment = u"a=$'abc\\''\n" + tokens = [ + (Token.Name.Variable, u'a'), + (Token.Operator, u'='), + (Token.Literal.String.Single, u"$'abc\\''"), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testShortVariableNames(self): + fragment = u'x="$"\ny="$_"\nz="$abc"\n' + tokens = [ + # single lone $ + (Token.Name.Variable, u'x'), + (Token.Operator, u'='), + (Token.Literal.String.Double, u'"'), + (Token.Text, u'$'), + (Token.Literal.String.Double, u'"'), + (Token.Text, u'\n'), + # single letter shell var + (Token.Name.Variable, u'y'), + (Token.Operator, u'='), + (Token.Literal.String.Double, u'"'), + (Token.Name.Variable, u'$_'), + (Token.Literal.String.Double, u'"'), + (Token.Text, u'\n'), + # multi-letter user var + (Token.Name.Variable, u'z'), + (Token.Operator, u'='), + (Token.Literal.String.Double, u'"'), + (Token.Name.Variable, u'$abc'), + (Token.Literal.String.Double, u'"'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testArrayNums(self): + fragment = u'a=(1 2 3)\n' + tokens = [ + (Token.Name.Variable, u'a'), + (Token.Operator, u'='), + (Token.Operator, u'('), + (Token.Literal.Number, u'1'), + (Token.Text, u' '), + (Token.Literal.Number, u'2'), + (Token.Text, u' '), + (Token.Literal.Number, u'3'), + (Token.Operator, u')'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testEndOfLineNums(self): + fragment = u'a=1\nb=2 # comment\n' + tokens = [ + (Token.Name.Variable, u'a'), + (Token.Operator, u'='), + (Token.Literal.Number, u'1'), + (Token.Text, u'\n'), + (Token.Name.Variable, u'b'), + (Token.Operator, u'='), + (Token.Literal.Number, u'2'), + (Token.Text, u' '), + (Token.Comment.Single, u'# comment\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + +class BashSessionTest(unittest.TestCase): + + def setUp(self): + self.lexer = BashSessionLexer() + self.maxDiff = None + + def testNeedsName(self): + fragment = u'$ echo \\\nhi\nhi\n' + tokens = [ + (Token.Text, u''), + (Token.Generic.Prompt, u'$'), + (Token.Text, u' '), + (Token.Name.Builtin, u'echo'), + (Token.Text, u' '), + (Token.Literal.String.Escape, u'\\\n'), + (Token.Text, u'hi'), + (Token.Text, u'\n'), + (Token.Generic.Output, u'hi\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_shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_shell.py') diff --git a/tests/test_shell.py b/tests/test_shell.py index 6faac9fd..e283793e 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -3,7 +3,7 @@ Basic Shell 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