diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-21 15:38:59 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-21 15:38:59 +0000 |
commit | da7976235fbc2986925969646071bebe3702e49f (patch) | |
tree | 83bbf6a8e03cf990369feabe6c1c9d45c69f4c85 /spec/ruby/core/enumerator | |
parent | b8e389a0f3226c90e96e02e6396686a3bef6a456 (diff) | |
download | ruby-da7976235fbc2986925969646071bebe3702e49f.tar.gz |
Update to ruby/spec@7a16e01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/enumerator')
18 files changed, 146 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerator/lazy/chunk_spec.rb b/spec/ruby/core/enumerator/lazy/chunk_spec.rb index 246dd72712..3f60c6ea3f 100644 --- a/spec/ruby/core/enumerator/lazy/chunk_spec.rb +++ b/spec/ruby/core/enumerator/lazy/chunk_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/chunk_while_spec.rb b/spec/ruby/core/enumerator/lazy/chunk_while_spec.rb new file mode 100644 index 0000000000..d555089872 --- /dev/null +++ b/spec/ruby/core/enumerator/lazy/chunk_while_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/drop_spec.rb b/spec/ruby/core/enumerator/lazy/drop_spec.rb index 8c15dea11d..822b8034fb 100644 --- a/spec/ruby/core/enumerator/lazy/drop_spec.rb +++ b/spec/ruby/core/enumerator/lazy/drop_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb index e29026be09..6f6472e393 100644 --- a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb +++ b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/force_spec.rb b/spec/ruby/core/enumerator/lazy/force_spec.rb index 15701d1fd7..a7fa029135 100644 --- a/spec/ruby/core/enumerator/lazy/force_spec.rb +++ b/spec/ruby/core/enumerator/lazy/force_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/grep_spec.rb b/spec/ruby/core/enumerator/lazy/grep_spec.rb index c46c760402..e759cc4a2c 100644 --- a/spec/ruby/core/enumerator/lazy/grep_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb index a0ec819505..13d474a8c4 100644 --- a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/lazy_spec.rb b/spec/ruby/core/enumerator/lazy/lazy_spec.rb index 5f386e2184..21fbfc27ab 100644 --- a/spec/ruby/core/enumerator/lazy/lazy_spec.rb +++ b/spec/ruby/core/enumerator/lazy/lazy_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/reject_spec.rb b/spec/ruby/core/enumerator/lazy/reject_spec.rb index 2661907b39..03444b471f 100644 --- a/spec/ruby/core/enumerator/lazy/reject_spec.rb +++ b/spec/ruby/core/enumerator/lazy/reject_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/shared/collect.rb b/spec/ruby/core/enumerator/lazy/shared/collect.rb index a686f30fd8..5690255a0c 100644 --- a/spec/ruby/core/enumerator/lazy/shared/collect.rb +++ b/spec/ruby/core/enumerator/lazy/shared/collect.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb index 26478f4ce0..e8ee4b6940 100644 --- a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb +++ b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/shared/select.rb b/spec/ruby/core/enumerator/lazy/shared/select.rb index 9127cf72b4..39074408ee 100644 --- a/spec/ruby/core/enumerator/lazy/shared/select.rb +++ b/spec/ruby/core/enumerator/lazy/shared/select.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/shared/to_enum.rb b/spec/ruby/core/enumerator/lazy/shared/to_enum.rb index a62a8ef90e..d488c9b263 100644 --- a/spec/ruby/core/enumerator/lazy/shared/to_enum.rb +++ b/spec/ruby/core/enumerator/lazy/shared/to_enum.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/slice_after_spec.rb b/spec/ruby/core/enumerator/lazy/slice_after_spec.rb new file mode 100644 index 0000000000..438df8d550 --- /dev/null +++ b/spec/ruby/core/enumerator/lazy/slice_after_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/slice_before_spec.rb b/spec/ruby/core/enumerator/lazy/slice_before_spec.rb new file mode 100644 index 0000000000..6c8660c1a1 --- /dev/null +++ b/spec/ruby/core/enumerator/lazy/slice_before_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/slice_when_spec.rb b/spec/ruby/core/enumerator/lazy/slice_when_spec.rb new file mode 100644 index 0000000000..e7673def47 --- /dev/null +++ b/spec/ruby/core/enumerator/lazy/slice_when_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/uniq_spec.rb b/spec/ruby/core/enumerator/lazy/uniq_spec.rb index fea2bec637..d337d063d6 100644 --- a/spec/ruby/core/enumerator/lazy/uniq_spec.rb +++ b/spec/ruby/core/enumerator/lazy/uniq_spec.rb @@ -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 diff --git a/spec/ruby/core/enumerator/lazy/zip_spec.rb b/spec/ruby/core/enumerator/lazy/zip_spec.rb index f3dbb63158..a28a7f5d5e 100644 --- a/spec/ruby/core/enumerator/lazy/zip_spec.rb +++ b/spec/ruby/core/enumerator/lazy/zip_spec.rb @@ -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 |