diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-13 21:55:12 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-15 01:09:06 +0900 |
| commit | e8896a31d48e5797df3878696dcb50aed85b87c2 (patch) | |
| tree | 4c8d7ed5ee5b8f6b517fe3dafb7fdcdd0dac3a73 /test | |
| parent | 3f492921c8b7c787b150445e4f28691d9a886dcc (diff) | |
[Bug #19877] Literals cannot have singleton methods even in blocks
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8440
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_parse.rb | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 957a37eb81..5209a4839f 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -453,11 +453,16 @@ class TestParse < Test::Unit::TestCase end def test_define_singleton_error - assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /singleton method for literals/) do - begin; - def ("foo").foo; end - end; - end + msg = /singleton method for literals/ + assert_parse_error(%q[def ("foo").foo; end], msg) + assert_parse_error(%q[def (1).foo; end], msg) + assert_parse_error(%q[def ((1;1)).foo; end], msg) + assert_parse_error(%q[def ((;1)).foo; end], msg) + assert_parse_error(%q[def ((1+1;1)).foo; end], msg) + assert_parse_error(%q[def ((%s();1)).foo; end], msg) + assert_parse_error(%q[def ((%w();1)).foo; end], msg) + assert_parse_error(%q[def ("#{42}").foo; end], msg) + assert_parse_error(%q[def (:"#{42}").foo; end], msg) end def test_op_asgn1_with_block @@ -1453,4 +1458,14 @@ x = __ENCODING__ assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} end =end + + def assert_parse(code) + assert_kind_of(RubyVM::AbstractSyntaxTree::Node, RubyVM::AbstractSyntaxTree.parse(code)) + end + + def assert_parse_error(code, message) + assert_raise_with_message(SyntaxError, message) do + RubyVM::AbstractSyntaxTree.parse(code) + end + end end |
