Skip to content

Commit

Permalink
Add type for Enumerator::Chain::new
Browse files Browse the repository at this point in the history
  • Loading branch information
ParadoxV5 committed Jan 2, 2025
1 parent d421a15 commit 3574120
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
19 changes: 10 additions & 9 deletions core/enumerator.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Check failure on line 615 in core/enumerator.rbs

View workflow job for this annotation

GitHub Actions / test (3.4, rubocop validate test_doc build test_generate_stdlib raap)

RBS/Lint/WillSyntaxError: `self` type is not allowed in this context
# {Enumerator::Chain#each} without block doesn't return `self`, unlike {Enumerator#each}
include Enumerator::_Each[Enum, self]

Check failure on line 617 in core/enumerator.rbs

View workflow job for this annotation

GitHub Actions / test (3.4, rubocop validate test_doc build test_generate_stdlib raap)

RBS/Lint/WillSyntaxError: `self` type is not allowed in this context

# <!--
# rdoc-file=enumerator.c
# - obj.each(*args) { |...| ... } -> obj
# - obj.each(*args) -> enumerator
# - Enumerator::Chain.new(*enums) -> enum
# -->
# 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
19 changes: 19 additions & 0 deletions test/stdlib/Enumerator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3574120

Please sign in to comment.