aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-04-08 18:45:50 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-30 12:39:31 -0700
commit896e42d93f52966644c2700ed9fd18f2a1988dd3 (patch)
treed3e4d052f3947dd92db466a43efbde45764dd6e4 /test
parent15bca0d4d373820fa648c351dc13c2131849d9b3 (diff)
downloadruby-896e42d93f52966644c2700ed9fd18f2a1988dd3.tar.gz
Restore splitting of hashes into positional and keyword arguments, add warning
This restores compatibility with Ruby 2.6, splitting the last positional hash into positional and keyword arguments if it contains both symbol and non-symbol keys. However, in this case it will warn, as the behavior in Ruby 3 will be to not split the hash and keep it as a positional argument. This does not affect the handling of mixed symbol and non-symbol keys in bare keywords. Those are still treated as keywords now, as they were before this patch. This results in different behavior than Ruby 2.6, which would split the bare keywords and use the non-Symbol keys as a positional arguments.
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_keyword.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index d0d64520e4..791d60b70a 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -284,6 +284,30 @@ class TestKeywordArguments < Test::Unit::TestCase
assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
end
+ def opt_plus_keyword(x=1, **h)
+ [x, h]
+ end
+
+ def splat_plus_keyword(*a, **h)
+ [a, h]
+ end
+
+ def test_keyword_split
+ 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))
+ assert_equal([1, {:a=>1}], opt_plus_keyword({:a=>1}))
+ assert_equal([{"a"=>1}, {}], opt_plus_keyword({"a"=>1}))
+ assert_equal([{"a"=>1}, {:a=>1}], opt_plus_keyword({"a"=>1, :a=>1}))
+
+ assert_equal([[], {:a=>1}], splat_plus_keyword(:a=>1))
+ assert_equal([[], {"a"=>1}], splat_plus_keyword("a"=>1))
+ assert_equal([[], {"a"=>1, :a=>1}], splat_plus_keyword("a"=>1, :a=>1))
+ assert_equal([[], {:a=>1}], splat_plus_keyword({:a=>1}))
+ assert_equal([[{"a"=>1}], {}], splat_plus_keyword({"a"=>1}))
+ assert_equal([[{"a"=>1}], {:a=>1}], splat_plus_keyword({"a"=>1, :a=>1}))
+ end
+
def test_bare_kwrest
# valid syntax, but its semantics is undefined
assert_valid_syntax("def bug7662(**) end")