summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-15 01:29:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-15 01:29:34 +0000
commitafcd5562ae7a61479b128845360151adc3c5397c (patch)
treeae5bf8a5c2f23ec3227b4698bf89b6762b0e4a38 /test
parent50a470b853dfc9dd72f80cbffbbe6fa5079d9970 (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_object.rb37
-rw-r--r--test/ruby/test_proc.rb2
2 files changed, 38 insertions, 1 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index db34d14479..d33b9f6341 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -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]'
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index efd5a269fd..3cac94a100 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -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