diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-15 09:25:03 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-15 09:25:03 +0000 |
commit | 032861ade7bdbe2c7e939b9b2995ed2ad1a1cdc6 (patch) | |
tree | c0987238bc8ffa9318d11ec41880bd29f1bfe30d /test/ruby/test_lazy_enumerator.rb | |
parent | ff1f6107f98261774739a6824fa80b1eba7b58ef (diff) |
* enumerator.c (lazy_zip, lazy_cycle): Enumerator::Lazy#{zip,cycle}
should be eager when a block is given, to be consistent with
Enumerable#{zip,cycle}.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_lazy_enumerator.rb')
-rw-r--r-- | test/ruby/test_lazy_enumerator.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 7450875fc0..f6fc870fb6 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -139,9 +139,12 @@ class TestLazyEnumerator < Test::Unit::TestCase end def test_zip_with_block + # zip should be eager when a block is given a = Step.new(1..3) - assert_equal(["a", 1], a.lazy.zip("a".."c") {|x, y| [y, x]}.first) - assert_equal(1, a.current) + ary = [] + assert_equal(nil, a.lazy.zip("a".."c") {|x, y| ary << [x, y]}) + assert_equal(a.zip("a".."c"), ary) + assert_equal(3, a.current) end def test_take @@ -190,8 +193,15 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal(3, a.current) assert_equal("1", a.lazy.cycle(2).map(&:to_s).first) assert_equal(1, a.current) - assert_equal("1", a.lazy.cycle(2, &:to_s).first) - assert_equal(1, a.current) + end + + def test_cycle_with_block + # cycle should be eager when a block is given + a = Step.new(1..3) + ary = [] + assert_equal(nil, a.lazy.cycle(2) {|i| ary << i}) + assert_equal(a.cycle(2).to_a, ary) + assert_equal(3, a.current) end def test_force |