From f725819666fea2eb3746f02ef81fca64f4b03992 Mon Sep 17 00:00:00 2001 From: mame Date: Sun, 8 Mar 2009 16:38:33 +0000 Subject: [PATCH] * test/ruby/test_enum.rb: add some tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ test/ruby/test_enum.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3606316eee..a53c16b3c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Mar 9 01:38:00 2009 Yusuke Endoh + + * test/ruby/test_enum.rb: add some tests. + Mon Mar 9 01:12:37 2009 Yusuke Endoh * test/ruby/test_object.rb: add a test for Object#method_missing. diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index a8a88640bd..8d22b12f03 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -48,6 +48,7 @@ class TestEnumerable < Test::Unit::TestCase assert_equal(1, @obj.find_index {|x| x % 2 == 0 }) assert_equal(nil, @obj.find_index {|x| false }) assert_raise(ArgumentError) { @obj.find_index(0, 1) } + assert_equal(1, @obj.find_index(2) {|x| x == 1 }) end def test_find_all @@ -212,6 +213,10 @@ class TestEnumerable < Test::Unit::TestCase @obj.zip([:a, :b, :c]) {|x,y| a << [x, y] } assert_equal([[1,:a],[2,:b],[3,:c],[1,nil],[2,nil]], a) + a = [] + @obj.zip({a: "A", b: "B", c: "C"}) {|x,y| a << [x, y] } + assert_equal([[1,[:a,"A"]],[2,[:b,"B"]],[3,[:c,"C"]],[1,nil],[2,nil]], a) + ary = Object.new def ary.to_a; [1, 2]; end assert_raise(NoMethodError){ %w(a b).zip(ary) } @@ -274,4 +279,8 @@ class TestEnumerable < Test::Unit::TestCase c.call end end + + def test_reverse_each + assert_equal([2,1,3,2,1], @obj.reverse_each.to_a) + end end