From c82ad6d20781630c9bf71fd811cade770691240e Mon Sep 17 00:00:00 2001 From: marcandre Date: Tue, 6 Nov 2012 17:12:35 +0000 Subject: * enum.c: Support for enumerators created by Enumerable with forwarding: find_all, reject, ... [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_enumerator.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ruby/test_enumerator.rb') diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index b2ef8e5c25..4757855533 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -10,6 +10,10 @@ class TestEnumerator < Test::Unit::TestCase a.each {|x| yield x } end end + @sized = @obj.clone + def @sized.size + 42 + end end def enum_test obj @@ -429,6 +433,16 @@ class TestEnumerator < Test::Unit::TestCase end end + def test_size_for_enum_created_from_enumerable + %i[find_all reject map flat_map partition group_by sort_by min_by max_by + minmax_by each_with_index reverse_each each_entry].each do |method| + assert_equal nil, @obj.send(method).size + assert_equal 42, @sized.send(method).size + end + assert_equal nil, @obj.each_with_object(nil).size + assert_equal 42, @sized.each_with_object(nil).size + end + def check_consistency_for_combinatorics(method) [ [], [:a, :b, :c, :d, :e] ].product([-2, 0, 2, 5, 6]) do |array, arg| assert_equal array.send(method, arg).to_a.size, array.send(method, arg).size, -- cgit v1.2.3