summaryrefslogtreecommitdiff
path: root/tests/test_ruby.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-10-06 19:46:21 -0700
committerTim Hatch <tim@timhatch.com>2014-10-06 19:46:21 -0700
commitdb54045f07300a47e4a603687fdcef89f29a2b12 (patch)
treea19dfa01cd8a6ec09daf2b66304e124d89dac755 /tests/test_ruby.py
parent5bbc0d44482b05c9467b737c4e217d5501203fc7 (diff)
downloadpygments-db54045f07300a47e4a603687fdcef89f29a2b12.tar.gz
RubyLexer: Keep state with nested interpolations
Fixes #1018
Diffstat (limited to 'tests/test_ruby.py')
-rw-r--r--tests/test_ruby.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/test_ruby.py b/tests/test_ruby.py
index 8f719d10..8420826e 100644
--- a/tests/test_ruby.py
+++ b/tests/test_ruby.py
@@ -9,7 +9,7 @@
import unittest
-from pygments.token import Operator, Number, Text
+from pygments.token import Operator, Number, Text, Token
from pygments.lexers import RubyLexer
@@ -50,3 +50,64 @@ class RubyTest(unittest.TestCase):
]
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+ def testInterpolationNestedCurly(self):
+ fragment = (
+ u'"A#{ (3..5).group_by { |x| x/2}.map '
+ u'do |k,v| "#{k}" end.join }" + "Z"\n')
+
+ tokens = [
+ (Token.Literal.String.Double, u'"'),
+ (Token.Literal.String.Double, u'A'),
+ (Token.Literal.String.Interpol, u'#{'),
+ (Token.Text, u' '),
+ (Token.Punctuation, u'('),
+ (Token.Literal.Number.Integer, u'3'),
+ (Token.Operator, u'..'),
+ (Token.Literal.Number.Integer, u'5'),
+ (Token.Punctuation, u')'),
+ (Token.Operator, u'.'),
+ (Token.Name, u'group_by'),
+ (Token.Text, u' '),
+ (Token.Literal.String.Interpol, u'{'),
+ (Token.Text, u' '),
+ (Token.Operator, u'|'),
+ (Token.Name, u'x'),
+ (Token.Operator, u'|'),
+ (Token.Text, u' '),
+ (Token.Name, u'x'),
+ (Token.Operator, u'/'),
+ (Token.Literal.Number.Integer, u'2'),
+ (Token.Literal.String.Interpol, u'}'),
+ (Token.Operator, u'.'),
+ (Token.Name, u'map'),
+ (Token.Text, u' '),
+ (Token.Keyword, u'do'),
+ (Token.Text, u' '),
+ (Token.Operator, u'|'),
+ (Token.Name, u'k'),
+ (Token.Punctuation, u','),
+ (Token.Name, u'v'),
+ (Token.Operator, u'|'),
+ (Token.Text, u' '),
+ (Token.Literal.String.Double, u'"'),
+ (Token.Literal.String.Interpol, u'#{'),
+ (Token.Name, u'k'),
+ (Token.Literal.String.Interpol, u'}'),
+ (Token.Literal.String.Double, u'"'),
+ (Token.Text, u' '),
+ (Token.Keyword, u'end'),
+ (Token.Operator, u'.'),
+ (Token.Name, u'join'),
+ (Token.Text, u' '),
+ (Token.Literal.String.Interpol, u'}'),
+ (Token.Literal.String.Double, u'"'),
+ (Token.Text, u' '),
+ (Token.Operator, u'+'),
+ (Token.Text, u' '),
+ (Token.Literal.String.Double, u'"'),
+ (Token.Literal.String.Double, u'Z'),
+ (Token.Literal.String.Double, u'"'),
+ (Token.Text, u'\n'),
+ ]
+ self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+