summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-10-12 00:26:39 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-10-12 00:40:55 +0900
commit4ed0c33d13ff0d2544aaf36e8e4f071b900d10cd (patch)
treede93b6343b6f4b7f7b17483018f0be5000d8db5e /test
parent27b48089e2bdc3b0719e75ae8685a496ef8fa9e3 (diff)
Prohibit setter method names in all kinds of endless methods
Also unwrap NODE_RIPPER to check the method name.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3649
Diffstat (limited to 'test')
-rw-r--r--test/ripper/test_parser_events.rb50
-rw-r--r--test/ruby/test_syntax.rb7
2 files changed, 50 insertions, 7 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 13064c2bc8..4e1d233851 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -660,11 +660,30 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
}
assert_equal true, thru_def
assert_equal '[def(foo,[],bodystmt([void()]))]', parse('def foo ;end')
+ end
- thru_def = false
- tree = parse('def foo() = 42', :on_def) {thru_def = true}
- assert_equal true, thru_def
+ def test_endless_def
+ events = %i[on_def on_parse_error]
+ thru = nil
+ hook = ->(name, *) {thru[name] = true}
+
+ thru = {}
+ tree = parse('def foo() = 42', events, &hook)
+ assert_equal({on_def: true}, thru)
assert_equal '[def(foo,[],42)]', tree
+
+ thru = {}
+ tree = parse('def foo() = 42 rescue 0', events, &hook)
+ assert_equal({on_def: true}, thru)
+ assert_equal '[def(foo,[],rescue_mod(42,0))]', tree
+
+ thru = {}
+ tree = parse('def foo=() = 42', events, &hook)
+ assert_equal({on_def: true, on_parse_error: true}, thru)
+
+ thru = {}
+ tree = parse('def foo=() = 42 rescue 0', events, &hook)
+ assert_equal({on_def: true, on_parse_error: true}, thru)
end
def test_defined
@@ -682,11 +701,30 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
thru_parse_error = false
tree = parse('def foo&.bar; end', :on_parse_error) {thru_parse_error = true}
assert_equal(true, thru_parse_error)
+ end
- thru_defs = false
- tree = parse('def foo.bar() = 42', :on_defs) {thru_defs = true}
- assert_equal true, thru_defs
+ def test_endless_defs
+ events = %i[on_defs on_parse_error]
+ thru = nil
+ hook = ->(name, *) {thru[name] = true}
+
+ thru = {}
+ tree = parse('def foo.bar() = 42', events, &hook)
+ assert_equal({on_defs: true}, thru)
assert_equal '[defs(vcall(foo),.,bar,[],42)]', tree
+
+ thru = {}
+ tree = parse('def foo.bar() = 42 rescue 0', events, &hook)
+ assert_equal({on_defs: true}, thru)
+ assert_equal '[defs(vcall(foo),.,bar,[],rescue_mod(42,0))]', tree
+
+ thru = {}
+ tree = parse('def foo.bar=() = 42', events, &hook)
+ assert_equal({on_defs: true, on_parse_error: true}, thru)
+
+ thru = {}
+ tree = parse('def foo.bar=() = 42 rescue 0', events, &hook)
+ assert_equal({on_defs: true, on_parse_error: true}, thru)
end
def test_do_block
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index fb982e8a1f..0542d4f90d 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1429,7 +1429,12 @@ eom
end
assert_equal("class ok", k.rescued("ok"))
assert_equal("instance ok", k.new.rescued("ok"))
- assert_syntax_error('def foo=() = 42', /setter method cannot be defined in an endless method definition/)
+
+ error = /setter method cannot be defined in an endless method definition/
+ assert_syntax_error('def foo=() = 42', error)
+ assert_syntax_error('def obj.foo=() = 42', error)
+ assert_syntax_error('def foo=() = 42 rescue nil', error)
+ assert_syntax_error('def obj.foo=() = 42 rescue nil', error)
end
def test_methoddef_in_cond