1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enumerator.c (lazy_flat_map_func): convert the block value to

Array if it doesn't respond to each.  [ruby-core:43334]
  [Bug #6155]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2012-03-19 08:22:29 +00:00
parent 592a629bd0
commit ded27bf5dc
3 changed files with 59 additions and 2 deletions

View file

@ -110,6 +110,27 @@ class TestLazyEnumerator < Test::Unit::TestCase
assert_equal(1, a.current)
end
def test_flat_map_to_ary
to_ary = Class.new {
def initialize(value)
@value = value
end
def to_ary
[:to_ary, @value]
end
}
assert_equal([:to_ary, 1, :to_ary, 2, :to_ary, 3],
[1, 2, 3].flat_map {|x| to_ary.new(x)})
assert_equal([:to_ary, 1, :to_ary, 2, :to_ary, 3],
[1, 2, 3].lazy.flat_map {|x| to_ary.new(x)}.force)
end
def test_flat_map_non_array
assert_equal(["1", "2", "3"], [1, 2, 3].flat_map {|x| x.to_s})
assert_equal(["1", "2", "3"], [1, 2, 3].lazy.flat_map {|x| x.to_s}.force)
end
def test_reject
a = Step.new(1..6)
assert_equal(4, a.reject {|x| x < 4}.first)