diff options
author | yui-knk <spiketeika@gmail.com> | 2022-11-17 23:43:21 +0900 |
---|---|---|
committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2022-11-18 18:25:42 +0900 |
commit | f0ce1186620273a1182e6084559765143099eb88 (patch) | |
tree | 8c78074e33cc1387827923003939c375a444431d /test | |
parent | ddd62fadaf91418cd259593285bc59358fb0b166 (diff) |
Make anonymous rest arg (*) and block arg (&) accessible from ARGS node
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6760
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_ast.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 7af6e43e1d..acf6722bb7 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -461,6 +461,30 @@ class TestAst < Test::Unit::TestCase assert_not_equal(type1, type2) end + def test_rest_arg + rest_arg = lambda do |arg_str| + node = RubyVM::AbstractSyntaxTree.parse("def a(#{arg_str}) end") + node = node.children.last.children.last.children[1].children[-4] + end + + assert_equal(nil, rest_arg.call('')) + assert_equal(:r, rest_arg.call('*r')) + assert_equal(:r, rest_arg.call('a, *r')) + assert_equal(:*, rest_arg.call('*')) + assert_equal(:*, rest_arg.call('a, *')) + end + + def test_block_arg + block_arg = lambda do |arg_str| + node = RubyVM::AbstractSyntaxTree.parse("def a(#{arg_str}) end") + node = node.children.last.children.last.children[1].children[-1] + end + + assert_equal(nil, block_arg.call('')) + assert_equal(:block, block_arg.call('&block')) + assert_equal(:&, block_arg.call('&')) + end + def test_keyword_rest kwrest = lambda do |arg_str| node = RubyVM::AbstractSyntaxTree.parse("def a(#{arg_str}) end") |