summaryrefslogtreecommitdiff
path: root/test/ruby/test_keyword.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-30 19:23:10 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-30 19:25:46 -0700
commit3463e83192215c36bdcebad8be907eaa09593a41 (patch)
tree8289f8b226d72dc1540827229bfbfbb53282180f /test/ruby/test_keyword.rb
parent6424d316b993ecceb6f583ae476096274e304788 (diff)
Warn for keyword to last hash parameter when method has no optional/rest parameters
Previously, there was no warning in this case, even though we will be changing the behavior in Ruby 3. Fixes [Bug #14130]
Diffstat (limited to 'test/ruby/test_keyword.rb')
-rw-r--r--test/ruby/test_keyword.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index ff95bc5354..2630983a71 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -22,7 +22,9 @@ class TestKeywordArguments < Test::Unit::TestCase
def test_f2
assert_equal([:xyz, "foo", 424242], f2(:xyz))
- assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42))
+ assert_warn(/The keyword argument for `f2' .* is passed as the last hash parameter/) do
+ assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42))
+ end
end
@@ -322,6 +324,10 @@ class TestKeywordArguments < Test::Unit::TestCase
end
end
+ def req_plus_keyword(x, **h)
+ [x, h]
+ end
+
def opt_plus_keyword(x=1, **h)
[x, h]
end
@@ -331,6 +337,19 @@ class TestKeywordArguments < Test::Unit::TestCase
end
def test_keyword_split
+ assert_warn(/The keyword argument for `req_plus_keyword' .* is passed as the last hash parameter/) do
+ assert_equal([{:a=>1}, {}], req_plus_keyword(:a=>1))
+ end
+ assert_warn(/The keyword argument for `req_plus_keyword' .* is passed as the last hash parameter/) do
+ assert_equal([{"a"=>1}, {}], req_plus_keyword("a"=>1))
+ end
+ assert_warn(/The keyword argument for `req_plus_keyword' .* is passed as the last hash parameter/) do
+ assert_equal([{"a"=>1, :a=>1}, {}], req_plus_keyword("a"=>1, :a=>1))
+ end
+ assert_equal([{:a=>1}, {}], req_plus_keyword({:a=>1}))
+ assert_equal([{"a"=>1}, {}], req_plus_keyword({"a"=>1}))
+ assert_equal([{"a"=>1, :a=>1}, {}], req_plus_keyword({"a"=>1, :a=>1}))
+
assert_equal([1, {:a=>1}], opt_plus_keyword(:a=>1))
assert_equal([1, {"a"=>1}], opt_plus_keyword("a"=>1))
assert_equal([1, {"a"=>1, :a=>1}], opt_plus_keyword("a"=>1, :a=>1))
@@ -536,7 +555,9 @@ class TestKeywordArguments < Test::Unit::TestCase
[a, b, c, d, e, f, g]
end
end
- assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993)
+ assert_warn(/The keyword argument for `foo' .* is passed as the last hash parameter/) do
+ assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993)
+ end
end
def test_splat_keyword_nondestructive