From 24065577943091e542a414d1841ffd1ef43b9add Mon Sep 17 00:00:00 2001 From: hsbt Date: Sat, 26 Apr 2014 02:53:54 +0000 Subject: * test/ruby/test_enum.rb (test_flat_map): Added test for flat_map. Contribute from @igaiga. [fix GH-598] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_enum.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/ruby/test_enum.rb') diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 963cd94034..7c8f37c8ce 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -592,4 +592,26 @@ class TestEnumerable < Test::Unit::TestCase assert_equal([['A',0], ['B',1], ['C',2], ['D',3], ['E',4]], @obj.each_with_index.map(&lambda2)) end + + def test_flat_map + @obj = [[1,2], [3,4]] + assert_equal([2,4,6,8], @obj.flat_map {|i| i.map{|j| j*2} }) + + proc = Proc.new {|i| i.map{|j| j*2} } + assert_equal([2,4,6,8], @obj.flat_map(&proc)) + + lambda = ->(i) { i.map{|j| j*2} } + assert_equal([2,4,6,8], @obj.flat_map(&lambda)) + + assert_equal([[1,2],0,[3,4],1], + @obj.each_with_index.flat_map {|x, i| [x,i] }) + + proc2 = Proc.new {|x, i| [x,i] } + assert_equal([[1,2],0,[3,4],1], + @obj.each_with_index.flat_map(&proc2)) + + lambda2 = ->(x, i) { [x,i] } + assert_equal([[1,2],0,[3,4],1], + @obj.each_with_index.flat_map(&lambda2)) + end end -- cgit v1.2.3