diff options
| author | Shugo Maeda <shugo@ruby-lang.org> | 2022-12-15 15:12:33 +0900 |
|---|---|---|
| committer | Shugo Maeda <shugo.maeda@gmail.com> | 2022-12-15 18:56:24 +0900 |
| commit | 2581de112c1957dc4b5852e54337551dc8972c99 (patch) | |
| tree | d276a3734bf323ab95ff5abab293935a05714033 /test/ruby | |
| parent | 613fca01486e47dee9364a2fd86b5f5e77fe23c8 (diff) | |
Disallow mixed usage of ... and */**
[Feature #19134]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6934
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_ast.rb | 4 | ||||
| -rw-r--r-- | test/ruby/test_syntax.rb | 32 |
2 files changed, 7 insertions, 29 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 667f8c0fd2..8acf4fe254 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -530,10 +530,10 @@ class TestAst < Test::Unit::TestCase forwarding = lambda do |arg_str| node = RubyVM::AbstractSyntaxTree.parse("def a(#{arg_str}) end") node = node.children.last.children.last.children[1] - node ? [node.children[-4], node.children[-2].children, node.children[-1]] : [] + node ? [node.children[-4], node.children[-2]&.children, node.children[-1]] : [] end - assert_equal([:*, [:**], :&], forwarding.call('...')) + assert_equal([:*, nil, :&], forwarding.call('...')) end def test_ranges_numbered_parameter diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 6695e46b92..f9416f8fcb 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -172,33 +172,11 @@ class TestSyntax < Test::Unit::TestCase end def test_argument_forwarding_with_anon_rest_kwrest_and_block - assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") - begin; - def args(*args); args end - def kw(**kw); kw end - def block(&block); block end - def deconstruct(...); [args(*), kw(**), block(&)&.call] end - assert_equal([[], {}, nil], deconstruct) - assert_equal([[1], {}, nil], deconstruct(1)) - assert_equal([[1, 2], {}, nil], deconstruct(1, 2)) - assert_equal([[], {x: 1}, nil], deconstruct(x: 1)) - assert_equal([[], {x: 1, y: 2}, nil], deconstruct(x: 1, y: 2)) - assert_equal([[], {}, 1], deconstruct { 1 }) - assert_equal([[1, 2], {x: 3, y: 4}, 5], deconstruct(1, 2, x: 3, y: 4) { 5 }) - end; - - assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") - begin; - def deconstruct(*args, **kw, &block); [args, kw, block&.call] end - def deconstruct2(*, **, &); deconstruct(...); end - assert_equal([[], {}, nil], deconstruct2) - assert_equal([[1], {}, nil], deconstruct2(1)) - assert_equal([[1, 2], {}, nil], deconstruct2(1, 2)) - assert_equal([[], {x: 1}, nil], deconstruct2(x: 1)) - assert_equal([[], {x: 1, y: 2}, nil], deconstruct2(x: 1, y: 2)) - assert_equal([[], {}, 1], deconstruct2 { 1 }) - assert_equal([[1, 2], {x: 3, y: 4}, 5], deconstruct2(1, 2, x: 3, y: 4) { 5 }) - end; + assert_syntax_error("def f(*, **, &); g(...); end", /unexpected \.\.\./) + assert_syntax_error("def f(...); g(*); end", /no anonymous rest parameter/) + assert_syntax_error("def f(...); g(0, *); end", /no anonymous rest parameter/) + assert_syntax_error("def f(...); g(**); end", /no anonymous keyword rest parameter/) + assert_syntax_error("def f(...); g(x: 1, **); end", /no anonymous keyword rest parameter/) end def test_newline_in_block_parameters |
