summaryrefslogtreecommitdiff
path: root/test/ruby/test_enumerator.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-08 15:26:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-08 15:26:01 +0000
commite1606102001b088e345c87f57dfa56d1c82a9118 (patch)
tree7b29f2b9b6cf20a9d779fcfb5f1170a1d4055b46 /test/ruby/test_enumerator.rb
parent0aa05d97b360a34533ea83df84f031645f655ede (diff)
* enumerator.c (enumerator_each, generator_each): pass arguments to
the block with yielder. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_enumerator.rb')
-rw-r--r--test/ruby/test_enumerator.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 10ba2f184e..a1ad22160c 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -238,6 +238,18 @@ class TestEnumerator < Test::Unit::TestCase
assert_equal([1,2], e.next_values)
end
+ def test_each_arg
+ o = Object.new
+ def o.each(ary)
+ ary << 1
+ yield
+ end
+ ary = []
+ e = o.to_enum.each(ary)
+ e.next
+ assert_equal([1], ary)
+ end
+
def test_feed
o = Object.new
def o.each(ary)
@@ -358,6 +370,13 @@ class TestEnumerator < Test::Unit::TestCase
assert_equal([1, 2, 3], a)
end
+ def test_generator_args
+ g = Enumerator::Generator.new {|y, x| y << 1 << 2 << 3; x }
+ a = []
+ assert_equal(:bar, g.each(:bar) {|x| a << x })
+ assert_equal([1, 2, 3], a)
+ end
+
def test_yielder
# note: Enumerator::Yielder is a class just for internal
a = []