summaryrefslogtreecommitdiff
path: root/tests/test_r.py
diff options
context:
space:
mode:
authorNikolay Korolev <korolevns98@gmail.com>2019-12-07 00:12:30 +0300
committerNikolay Korolev <korolevns98@gmail.com>2019-12-07 00:12:30 +0300
commitbfa88b52215aea2c889f70be9ab8dc6bdc67cd7b (patch)
treedbba7c40e2c5b8a2c1aea6db6d913e33f2919e93 /tests/test_r.py
parentce17db4bde5602157bf261385dfc9206ad5fc709 (diff)
downloadpygments-git-bfa88b52215aea2c889f70be9ab8dc6bdc67cd7b.tar.gz
Fix valid_name regex for SLexer
This fixes #1331 All modifications to regex: 1. Delete 2 useless non-capturing groups 2. Variables can not start with underscore (_) 3. Only letters, dot (.) and underscore (_) can go after first dot (.) in name 4. Name from only one symbol dot (.) is possible
Diffstat (limited to 'tests/test_r.py')
-rw-r--r--tests/test_r.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_r.py b/tests/test_r.py
index 72cb8afc..6dcc78e3 100644
--- a/tests/test_r.py
+++ b/tests/test_r.py
@@ -73,3 +73,40 @@ def test_custom_operator(lexer):
(Token.Text, u'\n'),
]
assert list(lexer.get_tokens(fragment)) == tokens
+
+
+def test_indexing(lexer):
+ fragment = u'a[1]'
+ tokens = [
+ (Token.Name, u'a'),
+ (Token.Punctuation, u'['),
+ (Token.Literal.Number, u'1'),
+ (Token.Punctuation, u']'),
+ (Token.Text, u'\n'),
+ ]
+ assert list(lexer.get_tokens(fragment)) == tokens
+
+
+def test_dot_name(lexer):
+ fragment = u'. <- 1'
+ tokens = [
+ (Token.Name, '.'),
+ (Token.Text, ' '),
+ (Token.Operator, '<-'),
+ (Token.Text, ' '),
+ (Token.Literal.Number, '1'),
+ (Token.Text, '\n')
+ ]
+ assert list(lexer.get_tokens(fragment)) == tokens
+
+
+def test_dot_indexing(lexer):
+ fragment = u'.[1]'
+ tokens = [
+ (Token.Name, u'.'),
+ (Token.Punctuation, u'['),
+ (Token.Literal.Number, u'1'),
+ (Token.Punctuation, u']'),
+ (Token.Text, u'\n'),
+ ]
+ assert list(lexer.get_tokens(fragment)) == tokens