summaryrefslogtreecommitdiffstats
path: root/tests/test_ruby.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:33:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:33:32 +0000
commit1f403ad2197fc7442409f434ee574f3e6b46fb73 (patch)
tree0299c6dd11d5edfa918a29b6456bc1875f1d288c /tests/test_ruby.py
parentInitial commit. (diff)
downloadpygments-upstream.tar.xz
pygments-upstream.zip
Adding upstream version 2.14.0+dfsg.upstream/2.14.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/test_ruby.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_ruby.py b/tests/test_ruby.py
new file mode 100644
index 0000000..a272926
--- /dev/null
+++ b/tests/test_ruby.py
@@ -0,0 +1,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)