summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-18 18:22:16 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-18 18:22:16 +0000
commitab4e82fedf32b722122d6a58be2b02e13f670de3 (patch)
tree579d2e450c44460f26ce1bfe71e41e3e1a21aad2 /test
parent28e43a93eec254975b97b4257465cf96a8b85d05 (diff)
merge revision(s) 41342,41359,41361: [Backport #8341]
test/ruby/test_proc.rb: tests for [Bug #8341] * include/ruby/intern.h, proc.c (rb_method_call_with_block): new function to invoke a Method object with a block passed as an argument. * proc.c (bmcall): use the above function to avoid a block sharing. [ruby-core:54626] [Bug #8341] * test/ruby/test_proc.rb (TestProc#test_block_persist_between_calls): run related tests. * test/ruby/test_proc.rb (TestProc#test_block_given_method_to_proc): run test for r41359. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@41392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_proc.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index dc426ddda5..9bd717153e 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -166,6 +166,14 @@ class TestProc < Test::Unit::TestCase
method(:m2).to_proc
end
+ def m1(var)
+ var
+ end
+
+ def m_block_given?
+ m1(block_given?)
+ end
+
# [yarv-dev:777] block made by Method#to_proc
def test_method_to_proc
b = block()
@@ -173,6 +181,37 @@ class TestProc < Test::Unit::TestCase
assert_instance_of(Binding, b.binding, '[ruby-core:25589]')
end
+ def test_block_given_method
+ m = method(:m_block_given?)
+ assert(!m.call, "without block")
+ assert(m.call {}, "with block")
+ assert(!m.call, "without block second")
+ end
+
+ def test_block_given_method_to_proc
+ bug8341 = '[Bug #8341]'
+ m = method(:m_block_given?).to_proc
+ assert(!m.call, "#{bug8341} without block")
+ assert(m.call {}, "#{bug8341} with block")
+ assert(!m.call, "#{bug8341} without block second")
+ end
+
+ def test_block_persist_between_calls
+ bug8341 = '[Bug #8341]'
+ o = Object.new
+ def o.m1(top=true)
+ if top
+ [block_given?, @m.call(false)]
+ else
+ block_given?
+ end
+ end
+ m = o.method(:m1).to_proc
+ o.instance_variable_set(:@m, m)
+ assert_equal([true, false], m.call {}, "#{bug8341} nested with block")
+ assert_equal([false, false], m.call, "#{bug8341} nested without block")
+ end
+
def test_curry
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
assert_equal(6, b.curry[1][2][3])