From ded27bf5dc25d61c1483ae2a79570b1435c8348b Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 19 Mar 2012 08:22:29 +0000 Subject: * 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 --- test/ruby/test_lazy_enumerator.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 0f2fa2bc41..5260043d43 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -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) -- cgit v1.2.3