summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-02 08:30:36 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-02 08:30:36 +0000
commitbb8532946030cb2e4337bd4f1f462e19ee507fa1 (patch)
tree8d60b3acf837bc51a22cb21c829cfbbeab72212c /spec/ruby
parent905189b2e3a7d746af91cdea254ed041a5fc111f (diff)
merge revision(s) 62731,62735: [Backport #14495]
Bug Fix Enumerator::Lazy#uniq state for multiple call * enumerator.c (lazy_uniq_i): create new hash for each calls. [Fix GH-1820] Currently 2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10} => #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq> 2.5.0-preview1 :002 > arr.to_a => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 2.5.0-preview1 :003 > arr.to_a => [] Expected arr.to_a to always return same output From: Anmol Chopra <anmolchopra@rocketbox.in> test_enumerator.rb: duplicate assertions * test/ruby/test_enumerator.rb (test_uniq): remove assertions which ared duplicate of lazy enumerator tests in test_lazy_enumerator.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@63824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/core/enumerator/lazy/uniq_spec.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerator/lazy/uniq_spec.rb b/spec/ruby/core/enumerator/lazy/uniq_spec.rb
index 6220c7ba34..391d2f6839 100644
--- a/spec/ruby/core/enumerator/lazy/uniq_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/uniq_spec.rb
@@ -3,6 +3,26 @@ require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '2.4' do
describe 'Enumerator::Lazy#uniq' do
+ context 'without block' do
+ before :each do
+ @lazy = [0, 1, 0, 1].to_enum.lazy.uniq
+ end
+
+ it 'returns a lazy enumerator' do
+ @lazy.should be_an_instance_of(Enumerator::Lazy)
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'return same value after rewind' do
+ @lazy.force.should == [0, 1]
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
+
context 'when yielded with an argument' do
before :each do
@lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
@@ -13,6 +33,11 @@ ruby_version_is '2.4' do
@lazy.force.should == [0, 1]
end
+ it 'return same value after rewind' do
+ @lazy.force.should == [0, 1]
+ @lazy.force.should == [0, 1]
+ end
+
it 'sets the size to nil' do
@lazy.size.should == nil
end
@@ -31,6 +56,12 @@ ruby_version_is '2.4' do
@lazy = enum.lazy
end
+ it 'return same value after rewind' do
+ enum = @lazy.uniq { |_, label| label.downcase }
+ enum.force.should == [[0, 'foo'], [2, 'bar']]
+ enum.force.should == [[0, 'foo'], [2, 'bar']]
+ end
+
it 'returns all yield arguments as an array' do
@lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
end