diff options
author | Kurt McKee <contactme@kurtmckee.org> | 2020-09-04 13:40:24 -0500 |
---|---|---|
committer | Kurt McKee <contactme@kurtmckee.org> | 2020-09-04 13:40:24 -0500 |
commit | d0edb537ca4b5f37c3ea6336ed2175d58e8c753a (patch) | |
tree | 00a848ef0529eaa3da46869880fdc452480088a8 /tests/test_ruby.py | |
parent | bc67241664df4082af20fc30f08af8d3b5158fc8 (diff) | |
download | pygments-git-d0edb537ca4b5f37c3ea6336ed2175d58e8c753a.tar.gz |
Support Ruby method names and operator overrides, including Unicode
Fixes #253
This patch contains these changes:
* Add 50+ new Ruby tests for method name/operator override matching.
* Unicode method names are now supported (#253).
* `=` method name postfixes are now supported.
* These operator overrides are now supported:
`<`, `<=`, `!` `!@`, `~@`, `!`, `!=`, `!~`, `=~`
* The `<>` "operator" override is removed. It appears that this was
a typo in the regular expression (`<=?>` should have been `<=>?`).
Syntax verified with https://docs.ruby-lang.org/en/2.7.0/syntax/methods_rdoc.html
Diffstat (limited to 'tests/test_ruby.py')
-rw-r--r-- | tests/test_ruby.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/test_ruby.py b/tests/test_ruby.py index 86a9ee77..9697bea8 100644 --- a/tests/test_ruby.py +++ b/tests/test_ruby.py @@ -9,8 +9,8 @@ import pytest -from pygments.token import Operator, Number, Text, Token -from pygments.lexers import RubyLexer +from pygments.token import Name, Number, Operator, Text, Token +from pygments.lexers.ruby import RubyLexer @pytest.fixture(scope='module') @@ -147,3 +147,39 @@ def test_escaped_bracestring(lexer): (Token.Text, u'\n'), ] assert list(lexer.get_tokens(fragment)) == tokens + + +@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) |