From 357412001c115869da29e2055be5783cbd66bc6b Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Wed, 1 Jan 2025 22:09:04 -0700 Subject: [PATCH] Add type for `Enumerator::Chain::new` --- core/enumerator.rbs | 19 ++++++++++--------- test/stdlib/Enumerator_test.rb | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/core/enumerator.rbs b/core/enumerator.rbs index c87367155..c1f6a3a1e 100644 --- a/core/enumerator.rbs +++ b/core/enumerator.rbs @@ -612,19 +612,20 @@ end # # This type of objects can be created by Enumerable#chain and Enumerator#+. # -class Enumerator::Chain[out Elem] < Enumerator[Elem, void] - include Enumerable[Elem] +class Enumerator::Chain[out Elem] < Enumerator[Elem, self] + # {Enumerator::Chain#each} without block doesn't return `self`, unlike {Enumerator#each} + include Enumerator::_Each[Enum, self] # - # Iterates over the elements of the first enumerable by calling the "each" - # method on it with the given arguments, then proceeds to the following - # enumerables in sequence until all of the enumerables are exhausted. + # Generates a new enumerator object that iterates over the elements of given + # enumerable objects in sequence. # - # If no block is given, returns an enumerator. + # e = Enumerator::Chain.new(1..3, [4, 5]) + # e.to_a #=> [1, 2, 3, 4, 5] + # e.size #=> 5 # - def each: () { (Elem) -> void } -> void + def initialize: (*_Each[Elem] enums) -> void end diff --git a/test/stdlib/Enumerator_test.rb b/test/stdlib/Enumerator_test.rb index 744bb4b63..f5c61d5fa 100644 --- a/test/stdlib/Enumerator_test.rb +++ b/test/stdlib/Enumerator_test.rb @@ -88,3 +88,22 @@ def test_to_proc end.next end end + +class EnumeratorChainTest < Test::Unit::TestCase + include TestHelper + + testing "::Enumerator::Chain[::Integer]" + + def test_class_new + assert_send_type "(*_Each[Integer] enums) -> Enumerator::Chain[Integer]", + Enumerator::Chain, :new, 1..3, [4, 5] + end + + def test_each + enum = Enumerator::Chain.new 1..3, [4, 5] + assert_send_type "() { (Integer) -> nil } -> Enumerator::Chain[Integer]", + enum, :each do end + assert_send_type "() -> Enumerator[Integer, Enumerator::Chain[Integer]]", + enum, :each + end +end