diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-08-25 13:42:35 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-11-25 16:11:17 +0900 |
commit | ffc6c5d056e0f18a9bdfb9b1477d0192a6d37ea3 (patch) | |
tree | c92824731591b307cb0af1bb34dc42fb39ecb233 /test/ruby | |
parent | 67d0f4821ff9ae550425a66202710d82de886384 (diff) | |
download | ruby-ffc6c5d056e0f18a9bdfb9b1477d0192a6d37ea3.tar.gz |
[Bug #18971] Add precheck to enumerator
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_lazy_enumerator.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 2116d0ee31..32bf097318 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -295,6 +295,26 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal(nil, a.current) end + def test_take_0_bug_18971 + def (bomb = Object.new.extend(Enumerable)).each + raise + end + [2..10, bomb].each do |e| + assert_equal([], e.lazy.take(0).map(&:itself).to_a) + assert_equal([], e.lazy.take(0).select(&:even?).to_a) + assert_equal([], e.lazy.take(0).select(&:odd?).to_a) + assert_equal([], e.lazy.take(0).reject(&:even?).to_a) + assert_equal([], e.lazy.take(0).reject(&:odd?).to_a) + assert_equal([], e.lazy.take(0).take(1).to_a) + assert_equal([], e.lazy.take(0).take(0).take(1).to_a) + assert_equal([], e.lazy.take(0).drop(0).to_a) + assert_equal([], e.lazy.take(0).find_all {|_| true}.to_a) + assert_equal([], e.lazy.take(0).zip((12..20)).to_a) + assert_equal([], e.lazy.take(0).uniq.to_a) + assert_equal([], e.lazy.take(0).sort.to_a) + end + end + def test_take_bad_arg a = Step.new(1..10) assert_raise(ArgumentError) { a.lazy.take(-1) } |