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
|
# -*- coding: utf-8 -*-
"""
Basic RubyLexer Test
~~~~~~~~~~~~~~~~~~~~
:copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pytest
from pygments.token import Name
from pygments.lexers.ruby import RubyLexer
@pytest.fixture(scope='module')
def lexer():
yield RubyLexer()
@pytest.mark.parametrize(
'method_name',
(
# Bare, un-scoped method names
'a', 'A', 'z', 'Z', 'は', '\u0080', '\uffff',
'aは0_', 'はA__9', '\u0080はa0_', '\uffff__99Z',
# Method names with trailing characters
'aは!', 'はz?', 'はa=',
# Scoped method names
'self.a', 'String.は_', 'example.AZ09_!',
# Operator overrides
'+', '+@', '-', '-@', '!', '!@', '~', '~@',
'*', '**', '/', '%', '&', '^', '`',
'<=>', '<', '<<', '<=', '>', '>>', '>=',
'==', '!=', '===', '=~', '!~',
'[]', '[]=',
)
)
def test_positive_method_names(lexer, method_name):
"""Validate positive method name parsing."""
text = 'def ' + method_name
assert list(lexer.get_tokens(text))[-2] == (Name.Function, method_name.rpartition('.')[2])
@pytest.mark.parametrize('method_name', ('1', '_', '<>', '<<=', '>>=', '&&', '||', '==?', '==!', '===='))
def test_negative_method_names(lexer, method_name):
"""Validate negative method name parsing."""
text = 'def ' + method_name
assert list(lexer.get_tokens(text))[-2] != (Name.Function, method_name)
|