This repository has been archived by the owner on Oct 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_r.py
70 lines (60 loc) · 1.92 KB
/
test_r.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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)))