mirror of
https://github.com/ruby/ruby.git
synced 2025-09-20 11:03:58 +02:00
merge revision(s) r32855,r32857,r33493,r34554:
* vm_eval.c (check_funcall): try respond_to? first if redefined. [Bug #5158] * test/ruby/test_object.rb: tests that respond_to? returns false. * vm_eval.c (check_funcall): set array elements one-by-one to fix compile error with Fujitsu C Compiler 5.6 on Solaris 10 on Sparc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
50a470b853
commit
afcd5562ae
5 changed files with 72 additions and 7 deletions
|
@ -181,18 +181,30 @@ class TestObject < Test::Unit::TestCase
|
|||
o = Object.new
|
||||
def o.to_s; 1; end
|
||||
assert_raise(TypeError) { String(o) }
|
||||
def o.to_s; "o"; end
|
||||
assert_equal("o", String(o))
|
||||
def o.respond_to?(*) false; end
|
||||
assert_raise(TypeError) { String(o) }
|
||||
end
|
||||
|
||||
def test_check_convert_type
|
||||
o = Object.new
|
||||
def o.to_a; 1; end
|
||||
assert_raise(TypeError) { Array(o) }
|
||||
def o.to_a; [1]; end
|
||||
assert_equal([1], Array(o))
|
||||
def o.respond_to?(*) false; end
|
||||
assert_equal([o], Array(o))
|
||||
end
|
||||
|
||||
def test_to_integer
|
||||
o = Object.new
|
||||
def o.to_i; nil; end
|
||||
assert_raise(TypeError) { Integer(o) }
|
||||
def o.to_i; 42; end
|
||||
assert_equal(42, Integer(o))
|
||||
def o.respond_to?(*) false; end
|
||||
assert_raise(TypeError) { Integer(o) }
|
||||
end
|
||||
|
||||
class MyInteger
|
||||
|
@ -383,6 +395,31 @@ class TestObject < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_implicit_respond_to
|
||||
bug5158 = '[ruby-core:38799]'
|
||||
|
||||
p = Object.new
|
||||
|
||||
called = []
|
||||
p.singleton_class.class_eval do
|
||||
define_method(:to_ary) do
|
||||
called << [:to_ary, bug5158]
|
||||
end
|
||||
end
|
||||
[[p]].flatten
|
||||
assert_equal([[:to_ary, bug5158]], called, bug5158)
|
||||
|
||||
called = []
|
||||
p.singleton_class.class_eval do
|
||||
define_method(:respond_to?) do |*a|
|
||||
called << [:respond_to?, *a]
|
||||
false
|
||||
end
|
||||
end
|
||||
[[p]].flatten
|
||||
assert_equal([[:respond_to?, :to_ary, true]], called, bug5158)
|
||||
end
|
||||
|
||||
def test_method_missing_passed_block
|
||||
bug5731 = '[ruby-dev:44961]'
|
||||
|
||||
|
|
|
@ -787,7 +787,7 @@ class TestProc < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_splat_without_respond_to
|
||||
def (obj = Object.new).respond_to?(m); false end
|
||||
def (obj = Object.new).respond_to?(m,*); false end
|
||||
[obj].each do |a, b|
|
||||
assert_equal([obj, nil], [a, b], '[ruby-core:24139]')
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue