1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2019-02-21 15:38:59 +00:00
parent b8e389a0f3
commit da7976235f
75 changed files with 940 additions and 258 deletions

View file

@ -68,4 +68,10 @@ describe "Enumerator::Lazy#chunk" do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.chunk { |n| n.even? }.first(100).should ==
s.first(100).chunk { |n| n.even? }.to_a
end
end

View file

@ -0,0 +1,9 @@
require_relative '../../../spec_helper'
describe "Enumerator::Lazy#chunk_while" do
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.chunk_while { |a, b| false }.first(100).should ==
s.first(100).chunk_while { |a, b| false }.to_a
end
end

View file

@ -49,4 +49,10 @@ describe "Enumerator::Lazy#drop" do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.drop(100).first(100).should ==
s.first(200).drop(100)
end
end

View file

@ -57,4 +57,10 @@ describe "Enumerator::Lazy#drop_while" do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.drop_while { |n| n < 100 }.first(100).should ==
s.first(200).drop_while { |n| n < 100 }
end
end

View file

@ -27,4 +27,10 @@ describe "Enumerator::Lazy#force" do
ScratchPad.recorded.should == [:before_yield]
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.take(100).force.should ==
s.take(100)
end
end

View file

@ -79,4 +79,10 @@ describe "Enumerator::Lazy#grep" do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.grep(Numeric).first(100).should ==
s.first(100).grep(Numeric)
end
end

View file

@ -81,4 +81,10 @@ describe "Enumerator::Lazy#grep_v" do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.grep_v(String).first(100).should ==
s.first(100).grep_v(String)
end
end

View file

@ -6,6 +6,20 @@ describe "Enumerator::Lazy" do
it "is a subclass of Enumerator" do
Enumerator::Lazy.superclass.should equal(Enumerator)
end
it "defines lazy versions of a whitelist of Enumerator methods" do
lazy_methods = [
:chunk, :collect, :collect_concat, :drop, :drop_while, :enum_for,
:find_all, :flat_map, :force, :grep, :grep_v, :lazy, :map, :reject,
:select, :slice_after, :slice_before, :slice_when, :take, :take_while,
:to_enum, :zip
]
ruby_version_is "2.4" do
lazy_methods += [:chunk_while, :uniq]
end
Enumerator::Lazy.instance_methods(false).should include(*lazy_methods)
end
end
describe "Enumerator::Lazy#lazy" do

View file

@ -33,6 +33,18 @@ describe "Enumerator::Lazy#reject" do
end
end
it "lets exceptions raised in the block go through" do
lazy = 10.times.lazy.map do |i|
raise "foo"
end
lazy = lazy.reject(&:nil?)
-> {
lazy.first
}.should raise_error(RuntimeError, "foo")
end
it "calls the block with a gathered array when yield with multiple arguments" do
yields = []
@yieldsmixed.reject { |v| yields << v }.force
@ -57,4 +69,10 @@ describe "Enumerator::Lazy#reject" do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.reject { |n| false }.first(100).should ==
s.first(100).reject { |n| false }
end
end

View file

@ -53,4 +53,10 @@ describe :enumerator_lazy_collect, shared: true do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.send(@method) { |n| n }.first(100).should ==
s.first(100).send(@method) { |n| n }.to_a
end
end

View file

@ -69,4 +69,10 @@ describe :enumerator_lazy_collect_concat, shared: true do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.send(@method) { |n| [-n, +n] }.first(200).should ==
s.first(100).send(@method) { |n| [-n, +n] }.to_a
end
end

View file

@ -57,4 +57,10 @@ describe :enumerator_lazy_select, shared: true do
end
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.send(@method) { |n| true }.first(100).should ==
s.first(100).send(@method) { |n| true }
end
end

View file

@ -47,4 +47,10 @@ describe :enumerator_lazy_to_enum, shared: true do
@infinite.send(method, *args).should be_an_instance_of(Enumerator::Lazy)
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.send(@method, :with_index).first(100).should ==
s.first(100).to_enum.send(@method, :with_index).to_a
end
end

View file

@ -0,0 +1,9 @@
require_relative '../../../spec_helper'
describe "Enumerator::Lazy#slice_after" do
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.slice_after { |n| true }.first(100).should ==
s.first(100).slice_after { |n| true }.to_a
end
end

View file

@ -0,0 +1,9 @@
require_relative '../../../spec_helper'
describe "Enumerator::Lazy#slice_before" do
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.slice_before { |n| true }.first(100).should ==
s.first(100).slice_before { |n| true }.to_a
end
end

View file

@ -0,0 +1,9 @@
require_relative '../../../spec_helper'
describe "Enumerator::Lazy#slice_when" do
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.slice_when { |a, b| true }.first(100).should ==
s.first(100).slice_when { |a, b| true }.to_a
end
end

View file

@ -72,5 +72,11 @@ ruby_version_is '2.4' do
@lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
end
end
it "works with an infinite enumerable" do
s = 0..Float::INFINITY
s.lazy.uniq.first(100).should ==
s.first(100).uniq
end
end
end

View file

@ -71,4 +71,16 @@ describe "Enumerator::Lazy#zip" do
end
end
end
it "works with an infinite enumerable and an array" do
s = 0..Float::INFINITY
s.lazy.zip(0..1000).first(100).should ==
s.first(100).zip(0..100)
end
it "works with two infinite enumerables" do
s = 0..Float::INFINITY
s.lazy.zip(s).first(100).should ==
s.first(100).zip(s)
end
end