summaryrefslogtreecommitdiff
path: root/test/ruby/test_keyword.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-25 17:14:17 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-26 08:01:53 -0700
commit6b52959ef76f6f19e50c6f80f00c08bb0daf5c7c (patch)
tree51e113dbed60184f2d9c5abd8faa05b2e0885368 /test/ruby/test_keyword.rb
parent47d44510a3f5c6cfca69b3fc05d7f5f35b1b2784 (diff)
Fix keyword argument separation issues in Thread.new
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2484
Diffstat (limited to 'test/ruby/test_keyword.rb')
-rw-r--r--test/ruby/test_keyword.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index 1cfa982f0c..dbced97b7e 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -684,6 +684,86 @@ class TestKeywordArguments < Test::Unit::TestCase
assert_equal([1, h3], f[a: 1, **h2])
end
+ def test_Thread_new_kwsplat
+ Thread.report_on_exception = false
+ kw = {}
+ h = {:a=>1}
+ h2 = {'a'=>1}
+ h3 = {'a'=>1, :a=>1}
+
+ t = Thread
+ f = -> { true }
+ assert_equal(true, t.new(**{}, &f).value)
+ assert_equal(true, t.new(**kw, &f).value)
+ assert_raise(ArgumentError) { t.new(**h, &f).value }
+ assert_raise(ArgumentError) { t.new(a: 1, &f).value }
+ assert_raise(ArgumentError) { t.new(**h2, &f).value }
+ assert_raise(ArgumentError) { t.new(**h3, &f).value }
+
+ f = ->(a) { a }
+ assert_warn(/The keyword argument is passed as the last hash parameter/m) do
+ assert_equal(kw, t.new(**{}, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/m) do
+ assert_equal(kw, t.new(**kw, &f).value)
+ end
+ assert_equal(h, t.new(**h, &f).value)
+ assert_equal(h, t.new(a: 1, &f).value)
+ assert_equal(h2, t.new(**h2, &f).value)
+ assert_equal(h3, t.new(**h3, &f).value)
+ assert_equal(h3, t.new(a: 1, **h2, &f).value)
+
+ f = ->(**x) { x }
+ assert_equal(kw, t.new(**{}, &f).value)
+ assert_equal(kw, t.new(**kw, &f).value)
+ assert_equal(h, t.new(**h, &f).value)
+ assert_equal(h, t.new(a: 1, &f).value)
+ assert_equal(h2, t.new(**h2, &f).value)
+ assert_equal(h3, t.new(**h3, &f).value)
+ assert_equal(h3, t.new(a: 1, **h2, &f).value)
+ assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
+ assert_equal(h, t.new(h, &f).value)
+ end
+ assert_raise(ArgumentError) { t.new(h2, &f).value }
+ assert_warn(/The last argument is split into positional and keyword parameters.*for method/m) do
+ assert_raise(ArgumentError) { t.new(h3, &f).value }
+ end
+
+ f = ->(a, **x) { [a,x] }
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([{}, {}], t.new(**{}, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([{}, {}], t.new(**kw, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h, {}], t.new(**h, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h, {}], t.new(a: 1, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h2, {}], t.new(**h2, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h3, {}], t.new(**h3, &f).value)
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h3, {}], t.new(a: 1, **h2, &f).value)
+ end
+
+ f = ->(a=1, **x) { [a, x] }
+ assert_equal([1, kw], t.new(**{}, &f).value)
+ assert_equal([1, kw], t.new(**kw, &f).value)
+ assert_equal([1, h], t.new(**h, &f).value)
+ assert_equal([1, h], t.new(a: 1, &f).value)
+ assert_equal([1, h2], t.new(**h2, &f).value)
+ assert_equal([1, h3], t.new(**h3, &f).value)
+ assert_equal([1, h3], t.new(a: 1, **h2, &f).value)
+ ensure
+ Thread.report_on_exception = true
+ end
+
def test_Class_new_kwsplat_call
kw = {}
h = {:a=>1}