mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 22:14:37 +02:00
* 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
This commit is contained in:
parent
727024fbac
commit
c82ad6d207
2 changed files with 36 additions and 14 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue