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

Fix remaining warning issues in the tests due to keyword argument separation

This commit is contained in:
Jeremy Evans 2019-08-20 12:29:51 -07:00
parent 42adc5bc6b
commit 856bb3c35d
Notes: git 2019-08-31 04:40:14 +09:00
5 changed files with 64 additions and 25 deletions

View file

@ -414,10 +414,25 @@ tests = [
]
# normal path
tests.compact.each {|(insn, expr, *a)| assert_equal 'true', expr, insn, *a }
tests.compact.each do |(insn, expr, *a)|
if a.last.is_a?(Hash)
a = a.dup
kw = a.pop
assert_equal 'true', expr, insn, *a, **kw
else
assert_equal 'true', expr, insn, *a
end
end
# with trace
tests.compact.each {|(insn, expr, *a)|
progn = "set_trace_func(proc{})\n" + expr
assert_equal 'true', progn, 'trace_' + insn, *a
if a.last.is_a?(Hash)
a = a.dup
kw = a.pop
assert_equal 'true', progn, 'trace_' + insn, *a, **kw
else
assert_equal 'true', progn, 'trace_' + insn, *a
end
}

View file

@ -266,12 +266,12 @@ class TestCSVInterfaceRead < Test::Unit::TestCase
def test_options_not_modified
options = {}.freeze
CSV.foreach(@input.path, options)
CSV.open(@input.path, options) {}
CSV.parse("", options)
CSV.parse_line("", options)
CSV.read(@input.path, options)
CSV.readlines(@input.path, options)
CSV.table(@input.path, options)
CSV.foreach(@input.path, **options)
CSV.open(@input.path, **options) {}
CSV.parse("", **options)
CSV.parse_line("", **options)
CSV.read(@input.path, **options)
CSV.readlines(@input.path, **options)
CSV.table(@input.path, **options)
end
end

View file

@ -166,9 +166,9 @@ b|a|c
def test_options_not_modified
options = {}.freeze
CSV.generate(options) {}
CSV.generate_line([], options)
CSV.filter("", "", options)
CSV.instance("", options)
CSV.generate(**options) {}
CSV.generate_line([], **options)
CSV.filter("", "", **options)
CSV.instance("", **options)
end
end

View file

@ -302,14 +302,24 @@ class TestKeywordArguments < Test::Unit::TestCase
bug7665 = '[ruby-core:51278]'
bug8463 = '[ruby-core:55203] [Bug #8463]'
expect = [*%w[foo bar], {zzz: 42}]
assert_equal(expect, rest_keyrest(*expect), bug7665)
assert_warn(/The last argument for `rest_keyrest' .* is used as the keyword parameter/) do
assert_equal(expect, rest_keyrest(*expect), bug7665)
end
pr = proc {|*args, **opt| next *args, opt}
assert_equal(expect, pr.call(*expect), bug7665)
assert_equal(expect, pr.call(expect), bug8463)
assert_warn(/The last argument for `call' is used as the keyword parameter/) do
assert_equal(expect, pr.call(*expect), bug7665)
end
assert_warn(/The last argument for `call' is used as the keyword parameter/) do
assert_equal(expect, pr.call(expect), bug8463)
end
pr = proc {|a, *b, **opt| next a, *b, opt}
assert_equal(expect, pr.call(expect), bug8463)
assert_warn(/The last argument for `call' is used as the keyword parameter/) do
assert_equal(expect, pr.call(expect), bug8463)
end
pr = proc {|a, **opt| next a, opt}
assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
assert_warn(/The last argument for `call' is used as the keyword parameter/) do
assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
end
end
def opt_plus_keyword(x=1, **h)
@ -324,16 +334,24 @@ class TestKeywordArguments < Test::Unit::TestCase
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_warn(/The last argument for `opt_plus_keyword' .* is used as the keyword parameter/) do
assert_equal([1, {:a=>1}], opt_plus_keyword({:a=>1}))
end
assert_equal([{"a"=>1}, {}], opt_plus_keyword({"a"=>1}))
assert_equal([{"a"=>1}, {:a=>1}], opt_plus_keyword({"a"=>1, :a=>1}))
assert_warn(/The last argument for `opt_plus_keyword' .* is split into positional and keyword parameters/) do
assert_equal([{"a"=>1}, {:a=>1}], opt_plus_keyword({"a"=>1, :a=>1}))
end
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_warn(/The last argument for `splat_plus_keyword' .* is used as the keyword parameter/) do
assert_equal([[], {:a=>1}], splat_plus_keyword({:a=>1}))
end
assert_equal([[{"a"=>1}], {}], splat_plus_keyword({"a"=>1}))
assert_equal([[{"a"=>1}], {:a=>1}], splat_plus_keyword({"a"=>1, :a=>1}))
assert_warn(/The last argument for `splat_plus_keyword' .* is split into positional and keyword parameters/) do
assert_equal([[{"a"=>1}], {:a=>1}], splat_plus_keyword({"a"=>1, :a=>1}))
end
end
def test_bare_kwrest
@ -551,8 +569,12 @@ class TestKeywordArguments < Test::Unit::TestCase
o = Object.new
def o.to_hash() { k: 9 } end
assert_equal([1, 42, [], o, :key, {}, nil], f9(1, o))
assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016)
assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016)
assert_warn(/The last argument for `m1' .* is used as the keyword parameter/) do
assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016)
end
assert_warn(/The last argument for `m1' .* is used as the keyword parameter/) do
assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016)
end
end
def test_splat_hash

View file

@ -155,7 +155,9 @@ class TestSyntax < Test::Unit::TestCase
h = {k3: 31}
assert_raise(ArgumentError) {o.kw(**h)}
h = {"k1"=>11, k2: 12}
assert_raise(ArgumentError) {o.kw(**h)}
assert_warn(/The last argument for `kw' .* is split into positional and keyword parameters/) do
assert_raise(ArgumentError) {o.kw(**h)}
end
end
def test_keyword_duplicated