git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-06-29 14:35:37 +00:00
parent 6a4aa4838c
commit 5b593e3889
79 changed files with 1555 additions and 304 deletions

View file

@ -1,5 +1,17 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Enumerator#inspect" do
it "needs to be reviewed for spec completeness"
describe "shows a representation of the Enumerator" do
it "including receiver and method" do
(1..3).each.inspect.should == "#<Enumerator: 1..3:each>"
end
it "including receiver and method and arguments" do
(1..3).each_slice(2).inspect.should == "#<Enumerator: 1..3:each_slice(2)>"
end
it "including the nested Enumerator" do
(1..3).each.each_slice(2).inspect.should == "#<Enumerator: #<Enumerator: 1..3:each>:each_slice(2)>"
end
end
end

View file

@ -64,7 +64,7 @@ describe "Enumerator::Lazy#grep" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
it "stops after specified times when not given a block" do
it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep(Integer).grep(Object).first(3).should == [0, 1, 2]
@eventsmixed.grep(BasicObject).grep(Object).first(1)

View file

@ -63,7 +63,7 @@ ruby_version_is "2.3" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
it "stops after specified times when not given a block" do
it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2]
@eventsmixed.grep_v(Symbol).grep_v(String).first(1)

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '2.4' do
describe 'Enumerator::Lazy#uniq' do
context 'when yielded with an argument' do
before :each do
@lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
end
it 'returns a lazy enumerator' do
@lazy.should be_an_instance_of(Enumerator::Lazy)
@lazy.force.should == [0, 1]
end
it 'sets the size to nil' do
@lazy.size.should == nil
end
end
context 'when yielded with multiple arguments' do
before :each do
enum = Object.new.to_enum
class << enum
def each
yield 0, 'foo'
yield 1, 'FOO'
yield 2, 'bar'
end
end
@lazy = enum.lazy
end
it 'returns all yield arguments as an array' do
@lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
end
end
end
end