diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_method.rb | 20 | ||||
-rw-r--r-- | test/ruby/test_proc.rb | 17 |
2 files changed, 31 insertions, 6 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 80a2669633..5193ac6889 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -1064,14 +1064,28 @@ class TestMethod < Test::Unit::TestCase assert_equal(6, h.call(2)) end - def test_compose_with_nonproc_or_method + def test_compose_with_callable + c = Class.new { + def f(x) x * 2 end + } + c2 = Class.new { + def call(x) x + 1 end + } + f = c.new.method(:f) + g = f * c2.new + + assert_equal(6, g.call(2)) + end + + def test_compose_with_noncallable c = Class.new { def f(x) x * 2 end } f = c.new.method(:f) + g = f * 5 - assert_raise(TypeError) { - f * 5 + assert_raise(NoMethodError) { + g.call(2) } end end diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 7ea4556e8a..f70345ed74 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -1460,11 +1460,22 @@ class TestProc < Test::Unit::TestCase assert_equal(6, h.call(2)) end - def test_compose_with_nonproc_or_method + def test_compose_with_callable f = proc {|x| x * 2} + c = Class.new { + def call(x) x + 1 end + } + g = f * c.new + + assert_equal(6, g.call(2)) + end + + def test_compose_with_noncallable + f = proc {|x| x * 2} + g = f * 5 - assert_raise(TypeError) { - f * 5 + assert_raise(NoMethodError) { + g.call(2) } end end |