summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_ast.rb4
-rw-r--r--test/ruby/test_syntax.rb32
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