| 1 |
""" |
| 2 |
Basic RubyLexer Test |
| 3 |
~~~~~~~~~~~~~~~~~~~~ |
| 4 |
|
| 5 |
:copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
| 6 |
:license: BSD, see LICENSE for details. |
| 7 |
""" |
| 8 |
|
| 9 |
import pytest |
| 10 |
from pygments.token import Name |
| 11 |
from pygments.lexers.ruby import RubyLexer |
| 12 |
|
| 13 |
|
| 14 |
@pytest.fixture(scope='module') |
| 15 |
def lexer(): |
| 16 |
yield RubyLexer() |
| 17 |
|
| 18 |
|
| 19 |
@pytest.mark.parametrize( |
| 20 |
'method_name', |
| 21 |
( |
| 22 |
# Bare, un-scoped method names |
| 23 |
'a', 'A', 'z', 'Z', 'は', '\u0080', '\uffff', |
| 24 |
'aは0_', 'はA__9', '\u0080はa0_', '\uffff__99Z', |
| 25 |
|
| 26 |
# Method names with trailing characters |
| 27 |
'aは!', 'はz?', 'はa=', |
| 28 |
|
| 29 |
# Scoped method names |
| 30 |
'self.a', 'String.は_', 'example.AZ09_!', |
| 31 |
|
| 32 |
# Operator overrides |
| 33 |
'+', '+@', '-', '-@', '!', '!@', '~', '~@', |
| 34 |
'*', '**', '/', '%', '&', '^', '`', |
| 35 |
'<=>', '<', '<<', '<=', '>', '>>', '>=', |
| 36 |
'==', '!=', '===', '=~', '!~', |
| 37 |
'[]', '[]=', |
| 38 |
) |
| 39 |
) |
| 40 |
def test_positive_method_names(lexer, method_name): |
| 41 |
"""Validate positive method name parsing.""" |
| 42 |
|
| 43 |
text = 'def ' + method_name |
| 44 |
assert list(lexer.get_tokens(text))[-2] == (Name.Function, method_name.rpartition('.')[2]) |
| 45 |
|
| 46 |
|
| 47 |
@pytest.mark.parametrize('method_name', ('1', '_', '<>', '<<=', '>>=', '&&', '||', '==?', '==!', '====')) |
| 48 |
def test_negative_method_names(lexer, method_name): |
| 49 |
"""Validate negative method name parsing.""" |
| 50 |
|
| 51 |
text = 'def ' + method_name |
| 52 |
assert list(lexer.get_tokens(text))[-2] != (Name.Function, method_name) |