summaryrefslogtreecommitdiff
path: root/test/ruby/test_enumerator.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-29 21:33:59 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-30 07:06:42 -0700
commit3073404e741df19ae16248126640777ed36110e8 (patch)
tree3e47a5336c27487329f43205746b17b3f03e5276 /test/ruby/test_enumerator.rb
parent5ddc2ba13ed6964a0383894e3728dc1bc708c404 (diff)
Add rb_enumeratorize_with_size_kw and related macros
Currently, there is not a way to create a sized enumerator in C with a different set of arguments than provided by Ruby, and correctly handle keyword arguments. This function allows that. The need for this is fairly uncommon, but it occurs at least in Enumerator.produce, which takes arugments from Ruby but calls rb_enumeratorize_with_size with a different set of arguments.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2509
Diffstat (limited to 'test/ruby/test_enumerator.rb')
-rw-r--r--test/ruby/test_enumerator.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 1e306c33a2..65adb5a438 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -831,6 +831,14 @@ class TestEnumerator < Test::Unit::TestCase
assert_equal [1, 2, 3], enum.take(3)
assert_equal [1, 2], passed_args
+ # With initial keyword arguments
+ passed_args = []
+ enum = Enumerator.produce(a: 1, b: 1) { |obj| passed_args << obj; obj.shift if obj.respond_to?(:shift)}
+ assert_instance_of(Enumerator, enum)
+ assert_equal Float::INFINITY, enum.size
+ assert_equal [{b: 1}, [1], :a, nil], enum.take(4)
+ assert_equal [{b: 1}, [1], :a], passed_args
+
# Raising StopIteration
words = "The quick brown fox jumps over the lazy dog.".scan(/\w+/)
enum = Enumerator.produce { words.shift or raise StopIteration }