summaryrefslogtreecommitdiff
path: root/test/ripper
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-06-14 18:28:22 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-06-14 20:41:41 +0900
commit1a70973f7557af33bfca6e2edc5cd302937425a4 (patch)
tree3a94693ffc8bf2009764b376354667246a68fd0a /test/ripper
parent048f14221cc8498ea8e5e339b6744288788a0303 (diff)
ripper: Check if anonymous parameters defined [Bug #18828]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6016
Diffstat (limited to 'test/ripper')
-rw-r--r--test/ripper/test_parser_events.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 5bb8f120f2..1ea8d23378 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -155,6 +155,44 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
end
end
+ def test_anonymous_block_forwarding
+ thru_args_add_block = false
+ parse('def b(&); c(&); end', :on_args_add_block) {thru_args_add_block = true}
+ assert_equal true, thru_args_add_block
+ assert_match "no anonymous block parameter", compile_error('def b; c(&); end')
+ end
+
+ def test_anonymous_rest_forwarding
+ [
+ 'c(*)',
+ 'c(*, *)',
+ ].each do |code|
+ thru_args_add_star = false
+ src = "def b(*); #{code} end"
+ parse(src, :on_args_add_star) {thru_args_add_star = true}
+ assert_equal true, thru_args_add_star, src
+
+ src = "def b; #{code} end"
+ assert_match "no anonymous rest parameter", compile_error(src), src
+ end
+ end
+
+ def test_anonymous_keyword_rest_forwarding
+ [
+ 'c(**)',
+ 'c(k: 1, **)',
+ 'c(**, k: 1)',
+ ].each do |code|
+ thru_assoc_splat = false
+ src = "def b(**); #{code} end"
+ parse(src, :on_assoc_splat) {thru_assoc_splat = true}
+ assert_equal true, thru_assoc_splat, src
+
+ src = "def b; #{code} end"
+ assert_match "no anonymous keyword rest parameter", compile_error(src), src
+ end
+ end
+
def test_arg_paren
# FIXME
end