aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_enumerator.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-22 09:58:01 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-22 09:58:01 +0000
commit5dd0e54414f01c4a310ce469b016d53104c543da (patch)
tree73dfc17a8e2401dfece8c763b9dc9a401ebe0287 /test/ruby/test_enumerator.rb
parent4f6434338ab43a5d033b769f6e2c65d0d1e5f345 (diff)
downloadruby-5dd0e54414f01c4a310ce469b016d53104c543da.tar.gz
Kernel#loop returns the result value of a finished iterator
* vm_eval.c (rb_f_loop): When a loop is stopped by a StopIteration exception, return what the enumerator has returned instead of nil. [ruby-core:71133] [Feature #11498] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_enumerator.rb')
-rw-r--r--test/ruby/test_enumerator.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 91c91a4bbd..e81d2e4e72 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -46,6 +46,14 @@ class TestEnumerator < Test::Unit::TestCase
}
end
+ def test_loop_return_value
+ assert_equal nil, loop { break }
+ assert_equal 42, loop { break 42 }
+
+ e = Enumerator.new { |y| y << 1; y << 2; :stopped }
+ assert_equal :stopped, loop { e.next while true }
+ end
+
def test_nested_iteration
def (o = Object.new).each
yield :ok1