1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_call.rb
usa a078bbcc17 merge revision(s) 56469: [Backport #12860]
* compile.c (setup_args): duplicate splatting array if more
	  arguments present to obey left-to-right execution order.
	  [ruby-core:77701] [Bug# 12860]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@57210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-27 09:34:40 +00:00

42 lines
1 KiB
Ruby

require 'test/unit'
class TestCall < Test::Unit::TestCase
def aaa(a, b=100, *rest)
res = [a, b]
res += rest if rest
return res
end
def test_call
assert_raise(ArgumentError) {aaa()}
assert_raise(ArgumentError) {aaa}
assert_equal([1, 100], aaa(1))
assert_equal([1, 2], aaa(1, 2))
assert_equal([1, 2, 3, 4], aaa(1, 2, 3, 4))
assert_equal([1, 2, 3, 4], aaa(1, *[2, 3, 4]))
end
def test_callinfo
bug9622 = '[ruby-core:61422] [Bug #9622]'
o = Class.new do
def foo(*args)
bar(:foo, *args)
end
def bar(name)
name
end
end.new
e = assert_raise(ArgumentError) {o.foo(100)}
assert_nothing_raised(ArgumentError) {o.foo}
assert_raise_with_message(ArgumentError, e.message, bug9622) {o.foo(100)}
end
def test_call_splat_order
bug12860 = '[ruby-core:77701] [Bug# 12860]'
ary = [1, 2]
assert_equal([1, 2, 1], aaa(*ary, ary.shift), bug12860)
ary = [1, 2]
assert_equal([0, 1, 2, 1], aaa(0, *ary, ary.shift), bug12860)
end
end