1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Update tests for full keyword argument separation

This commit is contained in:
Jeremy Evans 2019-10-04 15:41:13 -07:00
parent beae6cbf0f
commit ff96565686
Notes: git 2020-01-03 11:41:09 +09:00
12 changed files with 556 additions and 1694 deletions

View file

@ -24,14 +24,10 @@ class TestFuncall < Test::Unit::TestCase
def test_with_funcall_passing_block_kw
block = ->(*a, **kw) { [a, kw] }
assert_equal([[1], {}], Relay.with_funcall_passing_block_kw(0, 1, &block))
assert_equal([[{a: 1}], {}], Relay.with_funcall_passing_block_kw(0, a: 1, &block))
assert_equal([[], {a: 1}], Relay.with_funcall_passing_block_kw(1, a: 1, &block))
assert_equal([[1], {a: 1}], Relay.with_funcall_passing_block_kw(1, 1, a: 1, &block))
assert_equal([[{}], {}], Relay.with_funcall_passing_block_kw(2, {}, **{}, &block))
assert_equal([[], {a: 1}], Relay.with_funcall_passing_block_kw(3, a: 1, &block))
assert_equal([[{a: 1}], {}], Relay.with_funcall_passing_block_kw(3, {a: 1}, **{}, &block))
assert_warn(/warning: Passing the keyword argument as the last hash parameter is deprecated.*The called method is defined here/m) do
assert_equal({}, Relay.with_funcall_passing_block_kw(3, **{}, &->(a){a}))
end
end
def test_with_funcallv_public_kw
@ -47,29 +43,18 @@ class TestFuncall < Test::Unit::TestCase
arg
end
assert_equal([[1], {}], Relay.with_funcallv_public_kw(o, :foo, 0, 1))
assert_equal([[{a: 1}], {}], Relay.with_funcallv_public_kw(o, :foo, 0, a: 1))
assert_equal([[], {a: 1}], Relay.with_funcallv_public_kw(o, :foo, 1, a: 1))
assert_equal([[1], {a: 1}], Relay.with_funcallv_public_kw(o, :foo, 1, 1, a: 1))
assert_equal([[{}], {}], Relay.with_funcallv_public_kw(o, :foo, 2, {}, **{}))
assert_equal([[], {a: 1}], Relay.with_funcallv_public_kw(o, :foo, 3, a: 1))
assert_equal([[{a: 1}], {}], Relay.with_funcallv_public_kw(o, :foo, 3, {a: 1}, **{}))
assert_raise(NoMethodError) { Relay.with_funcallv_public_kw(o, :bar, 3, {a: 1}, **{}) }
assert_warn(/warning: Passing the keyword argument as the last hash parameter is deprecated.*The called method `baz'/m) do
assert_equal({}, Relay.with_funcallv_public_kw(o, :baz, 3, **{}))
end
end
def test_with_yield_splat_kw
block = ->(*a, **kw) { [a, kw] }
assert_equal([[1], {}], Relay.with_yield_splat_kw(0, [1], &block))
assert_equal([[{a: 1}], {}], Relay.with_yield_splat_kw(0, [{a: 1}], &block))
assert_equal([[], {a: 1}], Relay.with_yield_splat_kw(1, [{a: 1}], &block))
assert_equal([[1], {a: 1}], Relay.with_yield_splat_kw(1, [1, {a: 1}], &block))
assert_equal([[{}], {}], Relay.with_yield_splat_kw(2, [{}], **{}, &block))
assert_warn(/warning: Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal([[], {a: 1}], Relay.with_yield_splat_kw(3, [{a: 1}], &block))
end
assert_equal([[{a: 1}], {}], Relay.with_yield_splat_kw(3, [{a: 1}], **{}, &block))
assert_warn(/warning: Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal({}, Relay.with_yield_splat_kw(3, [], **{}, &->(a){a}))
end
assert_equal([[], {a: 1}], Relay.with_yield_splat_kw(3, [{a: 1}], &block))
end
end

View file

@ -93,14 +93,10 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([1, "a", nil], Bug::ScanArgs.lead_hash("a"))
assert_raise(ArgumentError) {Bug::ScanArgs.lead_hash("a", "b")}
assert_equal([1, "a", {b: 1}], Bug::ScanArgs.lead_hash("a", b: 1))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {b: 1}, nil], Bug::ScanArgs.lead_hash(b: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_hash(b: 1)}
assert_equal([1, {"a"=>0, b: 1}, nil], Bug::ScanArgs.lead_hash({"a"=>0, b: 1}, **{}))
assert_raise(ArgumentError) {Bug::ScanArgs.lead_hash(1, {"a"=>0, b: 1}, **{})}
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {}, nil], Bug::ScanArgs.lead_hash(**{}))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_hash(**{})}
end
def test_opt_hash
@ -109,9 +105,7 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([0, nil, {b: 1}], Bug::ScanArgs.opt_hash(b: 1))
assert_equal([1, "a", {b: 1}], Bug::ScanArgs.opt_hash("a", b: 1))
assert_raise(ArgumentError) {Bug::ScanArgs.opt_hash("a", "b")}
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([1, {"a"=>0}, {b: 1}], Bug::ScanArgs.opt_hash("a"=>0, b: 1))
end
assert_equal([0, nil, {"a"=>0, b: 1}], Bug::ScanArgs.opt_hash("a"=>0, b: 1))
assert_equal([1, {"a"=>0, b: 1}, nil], Bug::ScanArgs.opt_hash({"a"=>0, b: 1}, **{}))
end
@ -120,13 +114,9 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([2, "a", "b", nil], Bug::ScanArgs.lead_opt_hash("a", "b"))
assert_equal([1, "a", nil, {c: 1}], Bug::ScanArgs.lead_opt_hash("a", c: 1))
assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.lead_opt_hash("a", "b", c: 1))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {c: 1}, nil, nil], Bug::ScanArgs.lead_opt_hash(c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_hash(c: 1)}
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_hash("a", "b", "c")}
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([2, "a", {"b"=>0}, {c: 1}], Bug::ScanArgs.lead_opt_hash("a", "b"=>0, c: 1))
end
assert_equal([1, "a", nil, {"b"=>0, c: 1}], Bug::ScanArgs.lead_opt_hash("a", "b"=>0, c: 1))
end
def test_var_hash
@ -134,9 +124,7 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([1, ["a"], nil], Bug::ScanArgs.var_hash("a"))
assert_equal([1, ["a"], {b: 1}], Bug::ScanArgs.var_hash("a", b: 1))
assert_equal([0, [], {b: 1}], Bug::ScanArgs.var_hash(b: 1))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([1, [{"a"=>0}], {b: 1}], Bug::ScanArgs.var_hash("a"=>0, b: 1))
end
assert_equal([0, [], {"a"=>0, b: 1}], Bug::ScanArgs.var_hash("a"=>0, b: 1))
end
def test_lead_var_hash
@ -145,13 +133,9 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([2, "a", ["b"], nil], Bug::ScanArgs.lead_var_hash("a", "b"))
assert_equal([2, "a", ["b"], {c: 1}], Bug::ScanArgs.lead_var_hash("a", "b", c: 1))
assert_equal([1, "a", [], {c: 1}], Bug::ScanArgs.lead_var_hash("a", c: 1))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {c: 1}, [], nil], Bug::ScanArgs.lead_var_hash(c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_hash(c: 1)}
assert_equal([3, "a", ["b", "c"], nil], Bug::ScanArgs.lead_var_hash("a", "b", "c"))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([2, "a", [{"b"=>0}], {c: 1}], Bug::ScanArgs.lead_var_hash("a", "b"=>0, c: 1))
end
assert_equal([1, "a", [], {"b"=>0, c: 1}], Bug::ScanArgs.lead_var_hash("a", "b"=>0, c: 1))
end
def test_opt_var_hash
@ -162,9 +146,7 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([1, "a", [], {c: 1}], Bug::ScanArgs.opt_var_hash("a", c: 1))
assert_equal([0, nil, [], {c: 1}], Bug::ScanArgs.opt_var_hash(c: 1))
assert_equal([3, "a", ["b", "c"], nil], Bug::ScanArgs.opt_var_hash("a", "b", "c"))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([2, "a", [{"b"=>0}], {c: 1}], Bug::ScanArgs.opt_var_hash("a", "b"=>0, c: 1))
end
assert_equal([1, "a", [], {"b"=>0, c: 1}], Bug::ScanArgs.opt_var_hash("a", "b"=>0, c: 1))
end
def test_lead_opt_var_hash
@ -173,14 +155,10 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([2, "a", "b", [], nil], Bug::ScanArgs.lead_opt_var_hash("a", "b"))
assert_equal([2, "a", "b", [], {c: 1}], Bug::ScanArgs.lead_opt_var_hash("a", "b", c: 1))
assert_equal([1, "a", nil, [], {c: 1}], Bug::ScanArgs.lead_opt_var_hash("a", c: 1))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {c: 1}, nil, [], nil], Bug::ScanArgs.lead_opt_var_hash(c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_hash(c: 1)}
assert_equal([3, "a", "b", ["c"], nil], Bug::ScanArgs.lead_opt_var_hash("a", "b", "c"))
assert_equal([3, "a", "b", ["c"], {d: 1}], Bug::ScanArgs.lead_opt_var_hash("a", "b", "c", d: 1))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([3, "a", "b", [{"c"=>0}], {d: 1}], Bug::ScanArgs.lead_opt_var_hash("a", "b", "c"=>0, d: 1))
end
assert_equal([2, "a", "b", [], {"c"=>0, d: 1}], Bug::ScanArgs.lead_opt_var_hash("a", "b", "c"=>0, d: 1))
end
def test_opt_trail_hash
@ -189,13 +167,9 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([2, "a", "b", nil], Bug::ScanArgs.opt_trail_hash("a", "b"))
assert_equal([1, nil, "a", {c: 1}], Bug::ScanArgs.opt_trail_hash("a", c: 1))
assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.opt_trail_hash("a", "b", c: 1))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, nil, {c: 1}, nil], Bug::ScanArgs.opt_trail_hash(c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.opt_trail_hash(c: 1)}
assert_raise(ArgumentError) {Bug::ScanArgs.opt_trail_hash("a", "b", "c")}
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([2, "a", {"b"=>0}, {c: 1}], Bug::ScanArgs.opt_trail_hash("a", "b"=>0, c: 1))
end
assert_equal([1, nil, "a", {"b"=>0, c: 1}], Bug::ScanArgs.opt_trail_hash("a", "b"=>0, c: 1))
end
def test_lead_opt_trail_hash
@ -203,16 +177,12 @@ class TestScanArgs < Test::Unit::TestCase
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash("a")}
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash(c: 1)}
assert_equal([2, "a", nil, "b", nil], Bug::ScanArgs.lead_opt_trail_hash("a", "b"))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([2, "a", nil, {c: 1}, nil], Bug::ScanArgs.lead_opt_trail_hash("a", c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash("a", c: 1)}
assert_equal([2, "a", nil, "b", {c: 1}], Bug::ScanArgs.lead_opt_trail_hash("a", "b", c: 1))
assert_equal([3, "a", "b", "c", nil], Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c"))
assert_equal([3, "a", "b", "c", {c: 1}], Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c", c: 1))
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c", "d")}
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([3, "a", "b", {"c"=>0}, {c: 1}], Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c"=>0, c: 1))
end
assert_equal([2, "a", nil, "b", {"c"=>0, c: 1}], Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c"=>0, c: 1))
end
def test_var_trail_hash
@ -221,62 +191,46 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([2, ["a"], "b", nil], Bug::ScanArgs.var_trail_hash("a", "b"))
assert_equal([1, [], "a", {c: 1}], Bug::ScanArgs.var_trail_hash("a", c: 1))
assert_equal([2, ["a"], "b", {c: 1}], Bug::ScanArgs.var_trail_hash("a", "b", c: 1))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, [], {c: 1}, nil], Bug::ScanArgs.var_trail_hash(c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.var_trail_hash(c: 1)}
assert_equal([3, ["a", "b"], "c", nil], Bug::ScanArgs.var_trail_hash("a", "b", "c"))
assert_equal([3, ["a", "b"], "c", {c: 1}], Bug::ScanArgs.var_trail_hash("a", "b", "c", c: 1))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([3, ["a", "b"], {"c"=>0}, {c: 1}], Bug::ScanArgs.var_trail_hash("a", "b", "c"=>0, c: 1))
end
assert_equal([2, ["a"], "b", {"c"=>0, c: 1}], Bug::ScanArgs.var_trail_hash("a", "b", "c"=>0, c: 1))
end
def test_lead_var_trail_hash
assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash()}
assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash("a")}
assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash(c: 1)}
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([2, "a", [], {c: 1}, nil], Bug::ScanArgs.lead_var_trail_hash("a", c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash("a", c: 1)}
assert_equal([2, "a", [], "b", nil], Bug::ScanArgs.lead_var_trail_hash("a", "b"))
assert_equal([2, "a", [], "b", {c: 1}], Bug::ScanArgs.lead_var_trail_hash("a", "b", c: 1))
assert_equal([3, "a", ["b"], "c", nil], Bug::ScanArgs.lead_var_trail_hash("a", "b", "c"))
assert_equal([3, "a", ["b"], "c", {c: 1}], Bug::ScanArgs.lead_var_trail_hash("a", "b", "c", c: 1))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([3, "a", ["b"], {"c"=>0}, {c: 1}], Bug::ScanArgs.lead_var_trail_hash("a", "b", c: 1, "c"=>0))
end
assert_equal([2, "a", [], "b", {"c"=>0, c: 1}], Bug::ScanArgs.lead_var_trail_hash("a", "b", c: 1, "c"=>0))
end
def test_opt_var_trail_hash
assert_raise(ArgumentError) {Bug::ScanArgs.opt_var_trail_hash()}
assert_equal([1, nil, [], "a", nil], Bug::ScanArgs.opt_var_trail_hash("a"))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, nil, [], {c: 1}, nil], Bug::ScanArgs.opt_var_trail_hash(c: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.opt_var_trail_hash(c: 1)}
assert_equal([1, nil, [], "a", {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", c: 1))
assert_equal([2, "a", [], "b", nil], Bug::ScanArgs.opt_var_trail_hash("a", "b"))
assert_equal([2, "a", [], "b", {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", "b", c: 1))
assert_equal([3, "a", ["b"], "c", nil], Bug::ScanArgs.opt_var_trail_hash("a", "b", "c"))
assert_equal([3, "a", ["b"], "c", {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", "b", "c", c: 1))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([3, "a", ["b"], {"c"=>0}, {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", "b", "c"=>0, c: 1))
end
assert_equal([2, "a", [], "b", {"c"=>0, c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", "b", "c"=>0, c: 1))
end
def test_lead_opt_var_trail_hash
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_trail_hash()}
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_trail_hash("a")}
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([2, "a", nil, [], {b: 1}, nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", b: 1))
end
assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_trail_hash("a", b: 1)}
assert_equal([2, "a", nil, [], "b", nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b"))
assert_equal([2, "a", nil, [], "b", {c: 1}], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", c: 1))
assert_equal([3, "a", "b", [], "c", nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c"))
assert_equal([3, "a", "b", [], "c", {c: 1}], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c", c: 1))
assert_equal([4, "a", "b", ["c"], "d", nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c", "d"))
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([4, "a", "b", ["c"], {"d"=>0}, {c: 1}], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c", "d"=>0, c: 1))
end
assert_equal([3, "a", "b", [], "c", {"d"=>0, c: 1}], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c", "d"=>0, c: 1))
end
def test_k_lead_opt_hash
@ -285,25 +239,8 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([1, "a", nil, {c: 1}], Bug::ScanArgs.k_lead_opt_hash("a", {c: 1}))
assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.k_lead_opt_hash("a", "b", c: 1))
assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.k_lead_opt_hash("a", "b", {c: 1}))
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {c: 1}, nil, nil], Bug::ScanArgs.k_lead_opt_hash(c: 1))
end
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([2, "a", {"b"=>0}, {c: 1}], Bug::ScanArgs.k_lead_opt_hash("a", "b"=>0, c: 1))
end
end
def test_e_lead_opt_hash
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated/) do
assert_equal([1, {}, nil, nil], Bug::ScanArgs.e_lead_opt_hash)
end
assert_equal([1, "a", nil, nil], Bug::ScanArgs.e_lead_opt_hash("a"))
assert_equal([2, "a", "b", nil], Bug::ScanArgs.e_lead_opt_hash("a", "b"))
assert_equal([2, "a", {c: 1}, nil], Bug::ScanArgs.e_lead_opt_hash("a", c: 1))
assert_raise(ArgumentError) {Bug::ScanArgs.e_lead_opt_hash("a", "b", c: 1)}
assert_equal([1, {c: 1}, nil, nil], Bug::ScanArgs.e_lead_opt_hash(c: 1))
assert_raise(ArgumentError) {Bug::ScanArgs.e_lead_opt_hash("a", "b", "c")}
assert_equal([2, "a", {"b"=>0, c: 1}, nil], Bug::ScanArgs.e_lead_opt_hash("a", "b"=>0, c: 1))
assert_raise(ArgumentError) {Bug::ScanArgs.k_lead_opt_hash(c: 1)}
assert_equal([1, "a", nil, {"b"=>0, c: 1}], Bug::ScanArgs.k_lead_opt_hash("a", "b"=>0, c: 1))
end
def test_n_lead_opt_hash
@ -314,11 +251,9 @@ class TestScanArgs < Test::Unit::TestCase
assert_equal([1, "a", nil, {c: 1}], Bug::ScanArgs.n_lead_opt_hash("a", {c: 1}))
assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.n_lead_opt_hash("a", "b", c: 1))
assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.n_lead_opt_hash("a", "b", {c: 1}))
assert_equal([1, {c: 1}, nil, nil], Bug::ScanArgs.n_lead_opt_hash(c: 1))
assert_equal([1, {c: 1}, nil, nil], Bug::ScanArgs.n_lead_opt_hash({c: 1}))
assert_raise(ArgumentError) {Bug::ScanArgs.n_lead_opt_hash(c: 1)}
assert_raise(ArgumentError) {Bug::ScanArgs.n_lead_opt_hash({c: 1})}
assert_raise(ArgumentError) {Bug::ScanArgs.n_lead_opt_hash("a", "b", "c")}
assert_warn(/The last argument is split into positional and keyword parameters/) do
assert_equal([2, "a", {"b"=>0}, {c: 1}], Bug::ScanArgs.n_lead_opt_hash("a", "b"=>0, c: 1))
end
assert_equal([1, "a", nil, {"b"=>0, c: 1}], Bug::ScanArgs.n_lead_opt_hash("a", "b"=>0, c: 1))
end
end

View file

@ -945,8 +945,7 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
assert_raise(ArgumentError) {warn("test warning", uplevel: -1)}
assert_in_out_err(["-e", "warn 'ok', uplevel: 1"], '', [], /warning:/)
warning = capture_warning_warn {warn("test warning", {uplevel: 0})}
assert_equal("#{__FILE__}:#{__LINE__-1}: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call\n", warning[0])
assert_match(/warning: The called method (?:`.*' )?is defined here|warning: test warning/, warning[1])
assert_match(/test warning.*{:uplevel=>0}/m, warning[0])
warning = capture_warning_warn {warn("test warning", **{uplevel: 0})}
assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0])
warning = capture_warning_warn {warn("test warning", {uplevel: 0}, **{})}

View file

@ -2284,26 +2284,14 @@ class TestIO < Test::Unit::TestCase
def o.to_open(**kw); kw; end
assert_equal({:a=>1}, open(o, a: 1))
w = /Using the last argument as keyword parameters is deprecated.*The called method `(to_)?open'/m
redefined = nil
w.singleton_class.define_method(:===) do |s|
match = super(s)
redefined = !$1
match
end
assert_warn(w) do
assert_equal({:a=>1}, open(o, {a: 1}))
end
assert_raise(ArgumentError) { open(o, {a: 1}) }
class << o
remove_method(:to_open)
end
def o.to_open(kw); kw; end
assert_equal({:a=>1}, open(o, a: 1))
unless redefined
assert_equal({:a=>1}, open(o, {a: 1}))
end
assert_equal({:a=>1}, open(o, {a: 1}))
end
def test_open_pipe
@ -3138,11 +3126,8 @@ __END__
assert_equal("\00f", File.read(path))
assert_equal(1, File.write(path, "f", 0, encoding: "UTF-8"))
assert_equal("ff", File.read(path))
assert_raise(TypeError) {
assert_warn(/The last argument is split into positional and keyword parameters/) do
File.write(path, "foo", Object.new => Object.new)
end
}
File.write(path, "foo", Object.new => Object.new)
assert_equal("foo", File.read(path))
end
end

File diff suppressed because it is too large Load diff

View file

@ -631,15 +631,16 @@ class TestMarshal < Test::Unit::TestCase
def test_no_internal_ids
opt = %w[--disable=gems]
args = [opt, 'Marshal.dump("",STDOUT)', true, true, encoding: Encoding::ASCII_8BIT]
out, err, status = EnvUtil.invoke_ruby(*args)
args = [opt, 'Marshal.dump("",STDOUT)', true, true]
kw = {encoding: Encoding::ASCII_8BIT}
out, err, status = EnvUtil.invoke_ruby(*args, **kw)
assert_empty(err)
assert_predicate(status, :success?)
expected = out
opt << "--enable=frozen-string-literal"
opt << "--debug=frozen-string-literal"
out, err, status = EnvUtil.invoke_ruby(*args)
out, err, status = EnvUtil.invoke_ruby(*args, **kw)
assert_empty(err)
assert_predicate(status, :success?)
assert_equal(expected, out)

View file

@ -293,12 +293,9 @@ class TestNumeric < Test::Unit::TestCase
assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11).size }
e = assert_warn(/Using the last argument as keyword parameters is deprecated/) {
1.step(10, {by: "1"})
}
assert_warn('') {
assert_raise(ArgumentError) {e.size}
}
e = 1.step(10, {by: "1"})
assert_raise(TypeError) {e.next}
assert_raise(TypeError) {e.size}
assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size)
assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size)

View file

@ -1501,29 +1501,15 @@ class TestProcKeywords < Test::Unit::TestCase
g = ->(kw) { kw.merge(:a=>2) }
assert_equal(2, (f >> g).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call(a: 3)[:a])
end
assert_raise(ArgumentError) { (f << g).call(a: 3)[:a] }
assert_equal(2, (f >> g).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(2, (f >> g).call({a: 3})[:a])
end
assert_raise(ArgumentError) { (f << g).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f >> g).call({a: 3})[:a] }
assert_equal(2, (g << f).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (g >> f).call(a: 3)[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(2, (g << f).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (g >> f).call({a: 3})[:a])
end
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated.*Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call(**{})[:a])
end
assert_raise(ArgumentError) { (g >> f).call(a: 3)[:a] }
assert_raise(ArgumentError) { (g << f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (g >> f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f << g).call(**{})[:a] }
assert_equal(2, (f >> g).call(**{})[:a])
end
@ -1531,29 +1517,15 @@ class TestProcKeywords < Test::Unit::TestCase
f = ->(**kw) { kw.merge(:a=>1) }.method(:call)
g = ->(kw) { kw.merge(:a=>2) }.method(:call)
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call(a: 3)[:a])
end
assert_raise(ArgumentError) { (f << g).call(a: 3)[:a] }
assert_equal(2, (f >> g).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(2, (f >> g).call({a: 3})[:a])
end
assert_raise(ArgumentError) { (f << g).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f >> g).call({a: 3})[:a] }
assert_equal(2, (g << f).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (g >> f).call(a: 3)[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(2, (g << f).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (g >> f).call({a: 3})[:a])
end
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated.*Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call(**{})[:a])
end
assert_raise(ArgumentError) { (g >> f).call(a: 3)[:a] }
assert_raise(ArgumentError) { (g << f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (g >> f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f << g).call(**{})[:a] }
assert_equal(2, (f >> g).call(**{})[:a])
end
@ -1565,29 +1537,15 @@ class TestProcKeywords < Test::Unit::TestCase
def g.<<(f) to_proc << f end
def g.>>(f) to_proc >> f end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call(a: 3)[:a])
end
assert_raise(ArgumentError) { (f << g).call(a: 3)[:a] }
assert_equal(2, (f >> g).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (f << g).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(2, (f >> g).call({a: 3})[:a])
end
assert_raise(ArgumentError) { (f << g).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f >> g).call({a: 3})[:a] }
assert_equal(2, (g << f).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (g >> f).call(a: 3)[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(2, (g << f).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method is defined here/m) do
assert_equal(1, (g >> f).call({a: 3})[:a])
end
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated.*The called method `call'/m) do
assert_equal(1, (f << g).call(**{})[:a])
end
assert_raise(ArgumentError) { (g >> f).call(a: 3)[:a] }
assert_raise(ArgumentError) { (g << f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (g >> f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f << g).call(**{})[:a] }
assert_equal(2, (f >> g).call(**{})[:a])
f = ->(kw) { kw.merge(:a=>1) }
@ -1598,29 +1556,15 @@ class TestProcKeywords < Test::Unit::TestCase
def g.>>(f) to_proc >> f end
assert_equal(1, (f << g).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(2, (f >> g).call(a: 3)[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(1, (f << g).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(2, (f >> g).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(2, (g << f).call(a: 3)[:a])
end
assert_raise(ArgumentError) { (f >> g).call(a: 3)[:a] }
assert_raise(ArgumentError) { (f << g).call({a: 3})[:a] }
assert_raise(ArgumentError) { (f >> g).call({a: 3})[:a] }
assert_raise(ArgumentError) { (g << f).call(a: 3)[:a] }
assert_equal(1, (g >> f).call(a: 3)[:a])
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(2, (g << f).call({a: 3})[:a])
end
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(1, (g >> f).call({a: 3})[:a])
end
assert_raise(ArgumentError) { (g << f).call({a: 3})[:a] }
assert_raise(ArgumentError) { (g >> f).call({a: 3})[:a] }
assert_equal(1, (f << g).call(**{})[:a])
assert_warn(/Passing the keyword argument as the last hash parameter is deprecated.*Using the last argument as keyword parameters is deprecated.*The called method `call'/m) do
assert_equal(2, (f >> g).call(**{})[:a])
end
assert_raise(ArgumentError) { (f >> g).call(**{})[:a] }
end
end

View file

@ -115,7 +115,7 @@ module TestStruct
assert_equal "#{@Struct}::KeywordInitTrue(keyword_init: true)", @Struct::KeywordInitTrue.inspect
# eval is needed to prevent the warning duplication filter
k = eval("Class.new(@Struct::KeywordInitFalse) {def initialize(**) end}")
assert_warn(/Using the last argument as keyword parameters is deprecated/) {k.new(a: 1, b: 2)}
assert_raise(ArgumentError) { k.new(a: 1, b: 2) }
k = Class.new(@Struct::KeywordInitTrue) {def initialize(**) end}
assert_warn('') {k.new(a: 1, b: 2)}

View file

@ -182,9 +182,7 @@ class TestSyntax < Test::Unit::TestCase
h = {k3: 31}
assert_raise(ArgumentError) {o.kw(**h)}
h = {"k1"=>11, k2: 12}
assert_warn(/Splitting the last argument into positional and keyword parameters is deprecated.*The called method `kw'/m) do
assert_raise(ArgumentError) {o.kw(**h)}
end
assert_raise(ArgumentError) {o.kw(**h)}
end
def test_keyword_duplicated
@ -199,7 +197,7 @@ class TestSyntax < Test::Unit::TestCase
assert_equal([1, 2], a, bug10315)
a.clear
r = nil
assert_warn(/duplicated/) {r = eval("a.f({k: a.add(1), k: a.add(2)})")}
assert_warn(/duplicated/) {r = eval("a.f(**{k: a.add(1), k: a.add(2)})")}
assert_equal(2, r)
assert_equal([1, 2], a, bug10315)
end
@ -1523,12 +1521,12 @@ eom
assert_warning('') {
assert_equal([[1, 2, 3], {k1: 4, k2: 5}], obj.foo(1, 2, 3, k1: 4, k2: 5))
}
warning = "warning: Using the last argument as keyword parameters is deprecated"
assert_warning(/\A\z|:(?!#{__LINE__+1})\d+: #{warning}/o) {
assert_equal([[], {}], obj.foo({}) {|*x| x})
array = obj == obj3 ? [] : [{}]
assert_warning('') {
assert_equal([array, {}], obj.foo({}) {|*x| x})
}
assert_warning(/\A\z|:(?!#{__LINE__+1})\d+: #{warning}/o) {
assert_equal([[], {}], obj.foo({}))
assert_warning('') {
assert_equal([array, {}], obj.foo({}))
}
assert_equal(-1, obj.method(:foo).arity)
parameters = obj.method(:foo).parameters

View file

@ -518,15 +518,15 @@ class TestGemRequire < Gem::TestCase
define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do
lib = File.realpath("../../../lib", __FILE__)
Dir.mktmpdir("warn_test") do |dir|
File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n")
File.write(dir + "/main.rb", "warn({x:1}, {y:2}, [])\n")
_, err = capture_subprocess_io do
system(@@ruby, "-w", "--disable=gems", "-I", lib, "-C", dir, "main.rb")
system(@@ruby, "-w", "-rpp", "--disable=gems", "-I", lib, "-C", dir, "-I.", "main.rb")
end
assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
assert_equal("{:x=>1}\n{:y=>2}\n", err)
_, err = capture_subprocess_io do
system(@@ruby, "-w", "--enable=gems", "-I", lib, "-C", dir, "main.rb")
system(@@ruby, "-w", "-rpp", "--enable=gems", "-I", lib, "-C", dir, "-I.", "main.rb")
end
assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
assert_equal("{:x=>1}\n{:y=>2}\n", err)
end
end
end

View file

@ -190,9 +190,7 @@ class TestDelegateClass < Test::Unit::TestCase
assert_equal([], d.bar)
assert_equal([[], {:a=>1}], d.foo(:a=>1))
assert_equal([{:a=>1}], d.bar(:a=>1))
assert_warn(/Using the last argument as keyword parameters is deprecated.*The called method `foo'/m) do
assert_equal([[], {:a=>1}], d.foo({:a=>1}))
end
assert_equal([[{:a=>1}], {}], d.foo({:a=>1}))
assert_equal([{:a=>1}], d.bar({:a=>1}))
end