summaryrefslogtreecommitdiff
path: root/test/ruby/test_keyword.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-25 17:57:00 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-26 08:01:53 -0700
commitb193041b992e5ce0ae1a07735fbdc53a739b5434 (patch)
treecde06d981ddba5b6dae7935cb7b8d6199b6733f6 /test/ruby/test_keyword.rb
parent6b52959ef76f6f19e50c6f80f00c08bb0daf5c7c (diff)
Fix keyword argument separation issues in Fiber#resume
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.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index dbced97b7e..4bda9d5fb8 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -764,6 +764,83 @@ class TestKeywordArguments < Test::Unit::TestCase
Thread.report_on_exception = true
end
+ def test_Fiber_resume_kwsplat
+ kw = {}
+ h = {:a=>1}
+ h2 = {'a'=>1}
+ h3 = {'a'=>1, :a=>1}
+
+ t = Fiber
+ f = -> { true }
+ assert_equal(true, t.new(&f).resume(**{}))
+ assert_equal(true, t.new(&f).resume(**kw))
+ assert_raise(ArgumentError) { t.new(&f).resume(**h) }
+ assert_raise(ArgumentError) { t.new(&f).resume(a: 1) }
+ assert_raise(ArgumentError) { t.new(&f).resume(**h2) }
+ assert_raise(ArgumentError) { t.new(&f).resume(**h3) }
+
+ f = ->(a) { a }
+ assert_warn(/The keyword argument is passed as the last hash parameter/m) do
+ assert_equal(kw, t.new(&f).resume(**{}))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/m) do
+ assert_equal(kw, t.new(&f).resume(**kw))
+ end
+ assert_equal(h, t.new(&f).resume(**h))
+ assert_equal(h, t.new(&f).resume(a: 1))
+ assert_equal(h2, t.new(&f).resume(**h2))
+ assert_equal(h3, t.new(&f).resume(**h3))
+ assert_equal(h3, t.new(&f).resume(a: 1, **h2))
+
+ f = ->(**x) { x }
+ assert_equal(kw, t.new(&f).resume(**{}))
+ assert_equal(kw, t.new(&f).resume(**kw))
+ assert_equal(h, t.new(&f).resume(**h))
+ assert_equal(h, t.new(&f).resume(a: 1))
+ assert_equal(h2, t.new(&f).resume(**h2))
+ assert_equal(h3, t.new(&f).resume(**h3))
+ assert_equal(h3, t.new(&f).resume(a: 1, **h2))
+ assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
+ assert_equal(h, t.new(&f).resume(h))
+ end
+ assert_raise(ArgumentError) { t.new(&f).resume(h2) }
+ assert_warn(/The last argument is split into positional and keyword parameters.*for method/m) do
+ assert_raise(ArgumentError) { t.new(&f).resume(h3) }
+ end
+
+ f = ->(a, **x) { [a,x] }
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([{}, {}], t.new(&f).resume(**{}))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([{}, {}], t.new(&f).resume(**kw))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h, {}], t.new(&f).resume(**h))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h, {}], t.new(&f).resume(a: 1))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h2, {}], t.new(&f).resume(**h2))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h3, {}], t.new(&f).resume(**h3))
+ end
+ assert_warn(/The keyword argument is passed as the last hash parameter/) do
+ assert_equal([h3, {}], t.new(&f).resume(a: 1, **h2))
+ end
+
+ f = ->(a=1, **x) { [a, x] }
+ assert_equal([1, kw], t.new(&f).resume(**{}))
+ assert_equal([1, kw], t.new(&f).resume(**kw))
+ assert_equal([1, h], t.new(&f).resume(**h))
+ assert_equal([1, h], t.new(&f).resume(a: 1))
+ assert_equal([1, h2], t.new(&f).resume(**h2))
+ assert_equal([1, h3], t.new(&f).resume(**h3))
+ assert_equal([1, h3], t.new(&f).resume(a: 1, **h2))
+ end
+
def test_Class_new_kwsplat_call
kw = {}
h = {:a=>1}