diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-15 14:20:27 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-15 14:20:27 +0000 |
commit | 2baeb78294ecc18f2889eaa3d9a74d6f37ba8791 (patch) | |
tree | 6568099b9e7402548a5aa54ea9b5210c80db7854 /test | |
parent | d135138f9b7b64dc49025e27b5a7c9f97b11fa6d (diff) | |
download | ruby-2baeb78294ecc18f2889eaa3d9a74d6f37ba8791.tar.gz |
* enum.c (rb_enum_values_pack): rename from enum_values_pack, and
remove static.
* enumerator.c (lazy_init_iterator, lazy_init_yielder,
lazy_select_func, lazy_reject_func, lazy_grep_func): handle
multiple values correctly.
* enumerator.c (lazy_grep): change the behavior when a block is
given, to be consistent with Enumerable#grep.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_lazy_enumerator.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 7064f3b178..b096821191 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -72,6 +72,18 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal("word", a.current) end + def test_select_multiple_values + e = Enumerator.new { |yielder| + for i in 1..5 + yielder.yield(i, i.to_s) + end + } + assert_equal([[2, "2"], [4, "4"]], + e.select {|x| x[0] % 2 == 0}) + assert_equal([[2, "2"], [4, "4"]], + e.lazy.select {|x| x[0] % 2 == 0}.force) + end + def test_map a = Step.new(1..3) assert_equal(2, a.map {|x| x * 2}.first) @@ -112,6 +124,18 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal(nil, a.current) end + def test_reject_multiple_values + e = Enumerator.new { |yielder| + for i in 1..5 + yielder.yield(i, i.to_s) + end + } + assert_equal([[2, "2"], [4, "4"]], + e.reject {|x| x[0] % 2 != 0}) + assert_equal([[2, "2"], [4, "4"]], + e.lazy.reject {|x| x[0] % 2 != 0}.force) + end + def test_grep a = Step.new('a'..'f') assert_equal('c', a.grep(/c/).first) @@ -122,6 +146,24 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal(%w[a e], a.lazy.grep(proc {|x| /[aeiou]/ =~ x}).to_a) end + def test_grep_with_block + a = Step.new('a'..'f') + assert_equal('C', a.grep(/c/) {|i| i.upcase}.first) + assert_equal('C', a.lazy.grep(/c/) {|i| i.upcase}.first) + end + + def test_grep_multiple_values + e = Enumerator.new { |yielder| + 3.times { |i| + yielder.yield(i, i.to_s) + } + } + assert_equal([[2, "2"]], e.grep(proc {|x| x == [2, "2"]})) + assert_equal([[2, "2"]], e.lazy.grep(proc {|x| x == [2, "2"]}).force) + assert_equal(["22"], + e.lazy.grep(proc {|x| x == [2, "2"]}, &:join).force) + end + def test_zip a = Step.new(1..3) assert_equal([1, "a"], a.zip("a".."c").first) |