[前][次][番号順一覧][スレッド一覧]

ruby-changes:29290

From: nobu <ko1@a...>
Date: Mon, 17 Jun 2013 10:01:17 +0900 (JST)
Subject: [ruby-changes:29290] nobu:r41342 (trunk): test/ruby/test_proc.rb: tests for [Bug #8341]

nobu	2013-06-17 10:01:07 +0900 (Mon, 17 Jun 2013)

  New Revision: 41342

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41342

  Log:
    test/ruby/test_proc.rb: tests for [Bug #8341]

  Modified files:
    trunk/test/ruby/test_proc.rb

Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 41341)
+++ test/ruby/test_proc.rb	(revision 41342)
@@ -167,6 +167,14 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L167
     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()
@@ -174,6 +182,37 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L182
     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])

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]