From 5c276e1cc91c5ab2a41fbf7827af2fed914a2bc0 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 27 Jul 2019 12:40:09 +0200 Subject: Update to ruby/spec@875a09e --- .../enumerator/arithmetic_sequence/new_spec.rb | 4 +-- spec/ruby/core/enumerator/chain/initialize_spec.rb | 2 +- spec/ruby/core/enumerator/chain/rewind_spec.rb | 4 +-- spec/ruby/core/enumerator/each_spec.rb | 2 +- spec/ruby/core/enumerator/each_with_index_spec.rb | 2 +- spec/ruby/core/enumerator/feed_spec.rb | 4 +-- spec/ruby/core/enumerator/generator/each_spec.rb | 2 +- .../core/enumerator/generator/initialize_spec.rb | 2 +- spec/ruby/core/enumerator/initialize_spec.rb | 4 +-- spec/ruby/core/enumerator/lazy/drop_while_spec.rb | 2 +- spec/ruby/core/enumerator/lazy/grep_spec.rb | 33 ++++++++++++++++++++++ spec/ruby/core/enumerator/lazy/grep_v_spec.rb | 33 ++++++++++++++++++++++ spec/ruby/core/enumerator/lazy/initialize_spec.rb | 6 ++-- spec/ruby/core/enumerator/lazy/reject_spec.rb | 2 +- .../core/enumerator/lazy/shared/collect_concat.rb | 2 +- spec/ruby/core/enumerator/lazy/shared/select.rb | 2 +- spec/ruby/core/enumerator/lazy/take_while_spec.rb | 2 +- spec/ruby/core/enumerator/lazy/zip_spec.rb | 2 +- spec/ruby/core/enumerator/next_spec.rb | 8 +++--- spec/ruby/core/enumerator/next_values_spec.rb | 2 +- spec/ruby/core/enumerator/peek_spec.rb | 2 +- spec/ruby/core/enumerator/peek_values_spec.rb | 2 +- spec/ruby/core/enumerator/rewind_spec.rb | 2 +- spec/ruby/core/enumerator/size_spec.rb | 2 +- spec/ruby/core/enumerator/with_index_spec.rb | 6 ++-- 25 files changed, 100 insertions(+), 34 deletions(-) (limited to 'spec/ruby/core/enumerator') diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb index 5a62d3f346..7227581fb9 100644 --- a/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb +++ b/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb @@ -3,7 +3,7 @@ require_relative '../../../spec_helper' ruby_version_is "2.6" do describe "Enumerator::ArithmeticSequence.new" do it "is not defined" do - lambda { + -> { Enumerator::ArithmeticSequence.new }.should raise_error(NoMethodError) end @@ -11,7 +11,7 @@ ruby_version_is "2.6" do describe "Enumerator::ArithmeticSequence.allocate" do it "is not defined" do - lambda { + -> { Enumerator::ArithmeticSequence.allocate }.should raise_error(TypeError, 'allocator undefined for Enumerator::ArithmeticSequence') end diff --git a/spec/ruby/core/enumerator/chain/initialize_spec.rb b/spec/ruby/core/enumerator/chain/initialize_spec.rb index 4ede1b8670..e5aa32fd02 100644 --- a/spec/ruby/core/enumerator/chain/initialize_spec.rb +++ b/spec/ruby/core/enumerator/chain/initialize_spec.rb @@ -24,7 +24,7 @@ ruby_version_is "2.6" do describe "on frozen instance" do it "raises a RuntimeError" do - lambda { + -> { @uninitialized.freeze.send(:initialize) }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerator/chain/rewind_spec.rb b/spec/ruby/core/enumerator/chain/rewind_spec.rb index c6b82c831f..951b364f07 100644 --- a/spec/ruby/core/enumerator/chain/rewind_spec.rb +++ b/spec/ruby/core/enumerator/chain/rewind_spec.rb @@ -36,7 +36,7 @@ ruby_version_is "2.6" do @obj.should_not_receive(:rewind) @second.should_receive(:rewind).and_raise(RuntimeError) @enum.each {} - lambda { @enum.rewind }.should raise_error(RuntimeError) + -> { @enum.rewind }.should raise_error(RuntimeError) end it "calls rewind only for objects that have actually been iterated on" do @@ -46,7 +46,7 @@ ruby_version_is "2.6" do @obj.should_receive(:rewind) @second.should_not_receive(:rewind) - lambda { @enum.each {} }.should raise_error(RuntimeError) + -> { @enum.each {} }.should raise_error(RuntimeError) @enum.rewind end end diff --git a/spec/ruby/core/enumerator/each_spec.rb b/spec/ruby/core/enumerator/each_spec.rb index f66951851e..d88c09cdb5 100644 --- a/spec/ruby/core/enumerator/each_spec.rb +++ b/spec/ruby/core/enumerator/each_spec.rb @@ -49,7 +49,7 @@ describe "Enumerator#each" do it "raises a NoMethodError if the object doesn't respond to #each" do enum = Object.new.to_enum - lambda do + -> do enum.each { |e| e } end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/enumerator/each_with_index_spec.rb b/spec/ruby/core/enumerator/each_with_index_spec.rb index 7332fd628b..96e53a2804 100644 --- a/spec/ruby/core/enumerator/each_with_index_spec.rb +++ b/spec/ruby/core/enumerator/each_with_index_spec.rb @@ -14,7 +14,7 @@ describe "Enumerator#each_with_index" do end it "raises an ArgumentError if passed extra arguments" do - lambda do + -> do [1].to_enum.each_with_index(:glark) end.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/enumerator/feed_spec.rb b/spec/ruby/core/enumerator/feed_spec.rb index 90f0af8f14..e387c6cd39 100644 --- a/spec/ruby/core/enumerator/feed_spec.rb +++ b/spec/ruby/core/enumerator/feed_spec.rb @@ -39,14 +39,14 @@ describe "Enumerator#feed" do it "raises a TypeError if called more than once without advancing the enumerator" do @enum.feed :a @enum.next - lambda { @enum.feed :b }.should raise_error(TypeError) + -> { @enum.feed :b }.should raise_error(TypeError) end it "sets the return value of Yielder#yield" do enum = Enumerator.new { |y| ScratchPad << y.yield } enum.next enum.feed :a - lambda { enum.next }.should raise_error(StopIteration) + -> { enum.next }.should raise_error(StopIteration) ScratchPad.recorded.should == [:a] end end diff --git a/spec/ruby/core/enumerator/generator/each_spec.rb b/spec/ruby/core/enumerator/generator/each_spec.rb index cbdf863bec..a43805dd16 100644 --- a/spec/ruby/core/enumerator/generator/each_spec.rb +++ b/spec/ruby/core/enumerator/generator/each_spec.rb @@ -21,7 +21,7 @@ describe "Enumerator::Generator#each" do end it "raises a LocalJumpError if no block given" do - lambda { @generator.each }.should raise_error(LocalJumpError) + -> { @generator.each }.should raise_error(LocalJumpError) end it "returns the block returned value" do diff --git a/spec/ruby/core/enumerator/generator/initialize_spec.rb b/spec/ruby/core/enumerator/generator/initialize_spec.rb index 38da37a479..f75c7d6f26 100644 --- a/spec/ruby/core/enumerator/generator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/generator/initialize_spec.rb @@ -18,7 +18,7 @@ describe "Enumerator::Generator#initialize" do describe "on frozen instance" do it "raises a RuntimeError" do - lambda { + -> { @uninitialized.freeze.send(:initialize) {} }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerator/initialize_spec.rb b/spec/ruby/core/enumerator/initialize_spec.rb index 1305f150dc..53bf5d4ef2 100644 --- a/spec/ruby/core/enumerator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/initialize_spec.rb @@ -48,12 +48,12 @@ describe "Enumerator#initialize" do end it "sets size to the given size if the given size is a Proc" do - @uninitialized.send(:initialize, lambda { 200 }) {}.size.should == 200 + @uninitialized.send(:initialize, -> { 200 }) {}.size.should == 200 end describe "on frozen instance" do it "raises a RuntimeError" do - lambda { + -> { @uninitialized.freeze.send(:initialize) {} }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb index 6f6472e393..4f6e366f88 100644 --- a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb +++ b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb @@ -40,7 +40,7 @@ describe "Enumerator::Lazy#drop_while" do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.drop_while }.should raise_error(ArgumentError) + -> { @yieldsmixed.drop_while }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/grep_spec.rb b/spec/ruby/core/enumerator/lazy/grep_spec.rb index e759cc4a2c..e67686c9a3 100644 --- a/spec/ruby/core/enumerator/lazy/grep_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_spec.rb @@ -33,6 +33,39 @@ describe "Enumerator::Lazy#grep" do Enumerator::Lazy.new(Object.new, 100) {}.grep(Object).size.should == nil end + it "sets $~ in the block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep(/b/) { |e| + e.should == "abc" + $&.should == "b" + }.force + + # Set by the failed match of "def" + $~.should == nil + end + + it "sets $~ in the next block with each" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep(/b/).each { |e| + e.should == "abc" + $&.should == "b" + } + + # Set by the failed match of "def" + $~.should == nil + end + + it "sets $~ in the next block with map" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep(/b/).map { |e| + e.should == "abc" + $&.should == "b" + }.force + + # Set by the failed match of "def" + $~.should == nil + end + describe "when the returned lazy enumerator is evaluated by Enumerable#first" do it "stops after specified times when not given a block" do (0..Float::INFINITY).lazy.grep(Integer).first(3).should == [0, 1, 2] diff --git a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb index 13d474a8c4..67173021bb 100644 --- a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb @@ -31,6 +31,39 @@ describe "Enumerator::Lazy#grep_v" do Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil end + it "sets $~ in the block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep_v(/e/) { |e| + e.should == "abc" + $~.should == nil + }.force + + # Set by the match of "def" + $&.should == "e" + end + + it "sets $~ in the next block with each" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep_v(/e/).each { |e| + e.should == "abc" + $~.should == nil + } + + # Set by the match of "def" + $&.should == "e" + end + + it "sets $~ in the next block with map" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep_v(/e/).map { |e| + e.should == "abc" + $~.should == nil + }.force + + # Set by the match of "def" + $&.should == "e" + end + describe "when the returned lazy enumerator is evaluated by Enumerable#first" do it "stops after specified times when not given a block" do (0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2] diff --git a/spec/ruby/core/enumerator/lazy/initialize_spec.rb b/spec/ruby/core/enumerator/lazy/initialize_spec.rb index 9fa6eff35a..88c66530b9 100644 --- a/spec/ruby/core/enumerator/lazy/initialize_spec.rb +++ b/spec/ruby/core/enumerator/lazy/initialize_spec.rb @@ -48,16 +48,16 @@ describe "Enumerator::Lazy#initialize" do end it "sets given size to own size if the given size is a Proc" do - @uninitialized.send(:initialize, @receiver, lambda { 200 }) {}.size.should == 200 + @uninitialized.send(:initialize, @receiver, -> { 200 }) {}.size.should == 200 end it "raises an ArgumentError when block is not given" do - lambda { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError) + -> { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError) end describe "on frozen instance" do it "raises a RuntimeError" do - lambda { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError) + -> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError) end end end diff --git a/spec/ruby/core/enumerator/lazy/reject_spec.rb b/spec/ruby/core/enumerator/lazy/reject_spec.rb index 03444b471f..0e1632d667 100644 --- a/spec/ruby/core/enumerator/lazy/reject_spec.rb +++ b/spec/ruby/core/enumerator/lazy/reject_spec.rb @@ -52,7 +52,7 @@ describe "Enumerator::Lazy#reject" do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.reject }.should raise_error(ArgumentError) + -> { @yieldsmixed.reject }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb index e8ee4b6940..00d7941a61 100644 --- a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb +++ b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb @@ -46,7 +46,7 @@ describe :enumerator_lazy_collect_concat, shared: true do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) + -> { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/shared/select.rb b/spec/ruby/core/enumerator/lazy/shared/select.rb index 39074408ee..50a00bcbf4 100644 --- a/spec/ruby/core/enumerator/lazy/shared/select.rb +++ b/spec/ruby/core/enumerator/lazy/shared/select.rb @@ -40,7 +40,7 @@ describe :enumerator_lazy_select, shared: true do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) + -> { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/take_while_spec.rb b/spec/ruby/core/enumerator/lazy/take_while_spec.rb index 412ff76787..bcea0b1419 100644 --- a/spec/ruby/core/enumerator/lazy/take_while_spec.rb +++ b/spec/ruby/core/enumerator/lazy/take_while_spec.rb @@ -40,7 +40,7 @@ describe "Enumerator::Lazy#take_while" do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.take_while }.should raise_error(ArgumentError) + -> { @yieldsmixed.take_while }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/zip_spec.rb b/spec/ruby/core/enumerator/lazy/zip_spec.rb index a28a7f5d5e..5a828c1dcc 100644 --- a/spec/ruby/core/enumerator/lazy/zip_spec.rb +++ b/spec/ruby/core/enumerator/lazy/zip_spec.rb @@ -44,7 +44,7 @@ describe "Enumerator::Lazy#zip" do end it "raises a TypeError if arguments contain non-list object" do - lambda { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError) + -> { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/next_spec.rb b/spec/ruby/core/enumerator/next_spec.rb index e0d3c0a39b..3e9ed8b015 100644 --- a/spec/ruby/core/enumerator/next_spec.rb +++ b/spec/ruby/core/enumerator/next_spec.rb @@ -13,14 +13,14 @@ describe "Enumerator#next" do it "raises a StopIteration exception at the end of the stream" do 3.times { @enum.next } - lambda { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) end it "cannot be called again until the enumerator is rewound" do 3.times { @enum.next } - lambda { @enum.next }.should raise_error(StopIteration) - lambda { @enum.next }.should raise_error(StopIteration) - lambda { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) @enum.rewind @enum.next.should == 1 end diff --git a/spec/ruby/core/enumerator/next_values_spec.rb b/spec/ruby/core/enumerator/next_values_spec.rb index 8b57332c28..201b5d323f 100644 --- a/spec/ruby/core/enumerator/next_values_spec.rb +++ b/spec/ruby/core/enumerator/next_values_spec.rb @@ -50,6 +50,6 @@ describe "Enumerator#next_values" do it "raises StopIteration if called on a finished enumerator" do 7.times { @e.next } - lambda { @e.next_values }.should raise_error(StopIteration) + -> { @e.next_values }.should raise_error(StopIteration) end end diff --git a/spec/ruby/core/enumerator/peek_spec.rb b/spec/ruby/core/enumerator/peek_spec.rb index 0e4f60893d..2334385437 100644 --- a/spec/ruby/core/enumerator/peek_spec.rb +++ b/spec/ruby/core/enumerator/peek_spec.rb @@ -31,6 +31,6 @@ describe "Enumerator#peek" do it "raises StopIteration if called on a finished enumerator" do 5.times { @e.next } - lambda { @e.peek }.should raise_error(StopIteration) + -> { @e.peek }.should raise_error(StopIteration) end end diff --git a/spec/ruby/core/enumerator/peek_values_spec.rb b/spec/ruby/core/enumerator/peek_values_spec.rb index 5c81b4e529..7865546515 100644 --- a/spec/ruby/core/enumerator/peek_values_spec.rb +++ b/spec/ruby/core/enumerator/peek_values_spec.rb @@ -52,6 +52,6 @@ describe "Enumerator#peek_values" do it "raises StopIteration if called on a finished enumerator" do 7.times { @e.next } - lambda { @e.peek_values }.should raise_error(StopIteration) + -> { @e.peek_values }.should raise_error(StopIteration) end end diff --git a/spec/ruby/core/enumerator/rewind_spec.rb b/spec/ruby/core/enumerator/rewind_spec.rb index 2a83b7c6ee..a105f2c619 100644 --- a/spec/ruby/core/enumerator/rewind_spec.rb +++ b/spec/ruby/core/enumerator/rewind_spec.rb @@ -49,7 +49,7 @@ describe "Enumerator#rewind" do obj = mock('rewinder') enum = obj.to_enum obj.should_receive(:each).at_most(1) - lambda { enum.rewind.should == enum }.should_not raise_error + -> { enum.rewind.should == enum }.should_not raise_error end end diff --git a/spec/ruby/core/enumerator/size_spec.rb b/spec/ruby/core/enumerator/size_spec.rb index 5729b9303d..6accd26a4e 100644 --- a/spec/ruby/core/enumerator/size_spec.rb +++ b/spec/ruby/core/enumerator/size_spec.rb @@ -11,7 +11,7 @@ describe "Enumerator#size" do it "returns returning value from size.call if set size is a Proc" do base_size = 100 - enum = Enumerator.new(lambda { base_size + 1 }) {} + enum = Enumerator.new(-> { base_size + 1 }) {} base_size = 200 enum.size.should == 201 base_size = 300 diff --git a/spec/ruby/core/enumerator/with_index_spec.rb b/spec/ruby/core/enumerator/with_index_spec.rb index ca9f5a133e..ac37cee508 100644 --- a/spec/ruby/core/enumerator/with_index_spec.rb +++ b/spec/ruby/core/enumerator/with_index_spec.rb @@ -14,13 +14,13 @@ describe "Enumerator#with_index" do end it "accepts an optional argument when given a block" do - lambda do + -> do @enum.with_index(1) { |f| f} end.should_not raise_error(ArgumentError) end it "accepts an optional argument when not given a block" do - lambda do + -> do @enum.with_index(1) end.should_not raise_error(ArgumentError) end @@ -36,7 +36,7 @@ describe "Enumerator#with_index" do end it "raises a TypeError when the argument cannot be converted to numeric" do - lambda do + -> do @enum.with_index('1') {|*i| i} end.should raise_error(TypeError) end -- cgit v1.2.3