diff options
author | Anteru <bitbucket@ca.sh13.net> | 2018-11-26 20:10:02 +0000 |
---|---|---|
committer | Anteru <bitbucket@ca.sh13.net> | 2018-11-26 20:10:02 +0000 |
commit | 66e96a022ddec473f024a19a41f2775e47a89210 (patch) | |
tree | 7e0aa062bf51d953b8d8095fee91a02dac7f4c79 /tests/test_r.py | |
parent | fbca936d422f4cb069c34451530854e717cf7b9c (diff) | |
parent | 1bbff78e786cfee4fb6e2f07ecb415d68e565964 (diff) | |
download | pygments-git-66e96a022ddec473f024a19a41f2775e47a89210.tar.gz |
Merged in jimhester/pygments-main (pull request #680)
SLexer improvements
Diffstat (limited to 'tests/test_r.py')
-rw-r--r-- | tests/test_r.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test_r.py b/tests/test_r.py new file mode 100644 index 00000000..d0e9090b --- /dev/null +++ b/tests/test_r.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +""" + R Tests + ~~~~~~~~~ + + :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest + +from pygments.lexers import SLexer +from pygments.token import Token, Name, Punctuation + + +class RTest(unittest.TestCase): + def setUp(self): + self.lexer = SLexer() + + def testCall(self): + fragment = u'f(1, a)\n' + tokens = [ + (Name.Function, u'f'), + (Punctuation, u'('), + (Token.Literal.Number, u'1'), + (Punctuation, u','), + (Token.Text, u' '), + (Token.Name, u'a'), + (Punctuation, u')'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testName1(self): + fragment = u'._a_2.c' + tokens = [ + (Name, u'._a_2.c'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testName2(self): + # Invalid names are valid if backticks are used + fragment = u'`.1 blah`' + tokens = [ + (Name, u'`.1 blah`'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testName3(self): + # Internal backticks can be escaped + fragment = u'`.1 \` blah`' + tokens = [ + (Name, u'`.1 \` blah`'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testCustomOperator(self): + fragment = u'7 % and % 8' + tokens = [ + (Token.Literal.Number, u'7'), + (Token.Text, u' '), + (Token.Operator, u'% and %'), + (Token.Text, u' '), + (Token.Literal.Number, u'8'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) |