diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-07-29 22:11:21 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-07-29 22:11:21 +0200 |
commit | 6998d758248d778fa95b008c78d05473e48b8428 (patch) | |
tree | 8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/core/proc | |
parent | 15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff) | |
download | ruby-6998d758248d778fa95b008c78d05473e48b8428.tar.gz |
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/core/proc')
-rw-r--r-- | spec/ruby/core/proc/compose_spec.rb | 216 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/compose.rb | 2 |
2 files changed, 108 insertions, 110 deletions
diff --git a/spec/ruby/core/proc/compose_spec.rb b/spec/ruby/core/proc/compose_spec.rb index 285e96192b..803a32af7b 100644 --- a/spec/ruby/core/proc/compose_spec.rb +++ b/spec/ruby/core/proc/compose_spec.rb @@ -1,156 +1,154 @@ require_relative '../../spec_helper' require_relative 'shared/compose' -ruby_version_is "2.6" do - describe "Proc#<<" do - it "returns a Proc that is the composition of self and the passed Proc" do - upcase = proc { |s| s.upcase } - succ = proc { |s| s.succ } +describe "Proc#<<" do + it "returns a Proc that is the composition of self and the passed Proc" do + upcase = proc { |s| s.upcase } + succ = proc { |s| s.succ } - (succ << upcase).call('Ruby').should == "RUBZ" - end + (succ << upcase).call('Ruby').should == "RUBZ" + end - it "calls passed Proc with arguments and then calls self with result" do - f = proc { |x| x * x } - g = proc { |x| x + x } + it "calls passed Proc with arguments and then calls self with result" do + f = proc { |x| x * x } + g = proc { |x| x + x } - (f << g).call(2).should == 16 - (g << f).call(2).should == 8 - end + (f << g).call(2).should == 16 + (g << f).call(2).should == 8 + end - it "accepts any callable object" do - inc = proc { |n| n + 1 } + it "accepts any callable object" do + inc = proc { |n| n + 1 } - double = Object.new - def double.call(n); n * 2; end + double = Object.new + def double.call(n); n * 2; end - (inc << double).call(3).should == 7 - end + (inc << double).call(3).should == 7 + end - it_behaves_like :proc_compose, :<<, -> { proc { |s| s.upcase } } + it_behaves_like :proc_compose, :<<, -> { proc { |s| s.upcase } } - describe "composition" do - it "is a Proc" do + describe "composition" do + it "is a Proc" do + f = proc { |x| x * x } + g = proc { |x| x + x } + + (f << g).is_a?(Proc).should == true + (f << g).should_not.lambda? + end + + ruby_version_is(''...'3.0') do + it "is a Proc when other is lambda" do f = proc { |x| x * x } - g = proc { |x| x + x } + g = -> x { x + x } (f << g).is_a?(Proc).should == true (f << g).should_not.lambda? end - ruby_version_is(''...'3.0') do - it "is a Proc when other is lambda" do - f = proc { |x| x * x } - g = -> x { x + x } - - (f << g).is_a?(Proc).should == true - (f << g).should_not.lambda? - end - - it "is a lambda when self is lambda" do - f = -> x { x * x } - g = proc { |x| x + x } + it "is a lambda when self is lambda" do + f = -> x { x * x } + g = proc { |x| x + x } - (f << g).is_a?(Proc).should == true - (f << g).should.lambda? - end + (f << g).is_a?(Proc).should == true + (f << g).should.lambda? end + end - ruby_version_is('3.0') do - it "is a lambda when parameter is lambda" do - f = -> x { x * x } - g = proc { |x| x + x } - lambda_proc = -> x { x } + ruby_version_is('3.0') do + it "is a lambda when parameter is lambda" do + f = -> x { x * x } + g = proc { |x| x + x } + lambda_proc = -> x { x } - (f << g).is_a?(Proc).should == true - (f << g).should_not.lambda? - (f << lambda_proc).should.lambda? - end + (f << g).is_a?(Proc).should == true + (f << g).should_not.lambda? + (f << lambda_proc).should.lambda? end + end - it "may accept multiple arguments" do - inc = proc { |n| n + 1 } - mul = proc { |n, m| n * m } + it "may accept multiple arguments" do + inc = proc { |n| n + 1 } + mul = proc { |n, m| n * m } - (inc << mul).call(2, 3).should == 7 - end + (inc << mul).call(2, 3).should == 7 + end - it "passes blocks to the second proc" do - ScratchPad.record [] - one = proc { |&arg| arg.call :one if arg } - two = proc { |&arg| arg.call :two if arg } - (one << two).call { |x| ScratchPad << x } - ScratchPad.recorded.should == [:two] - end + it "passes blocks to the second proc" do + ScratchPad.record [] + one = proc { |&arg| arg.call :one if arg } + two = proc { |&arg| arg.call :two if arg } + (one << two).call { |x| ScratchPad << x } + ScratchPad.recorded.should == [:two] end end +end - describe "Proc#>>" do - it "returns a Proc that is the composition of self and the passed Proc" do - upcase = proc { |s| s.upcase } - succ = proc { |s| s.succ } +describe "Proc#>>" do + it "returns a Proc that is the composition of self and the passed Proc" do + upcase = proc { |s| s.upcase } + succ = proc { |s| s.succ } - (succ >> upcase).call('Ruby').should == "RUBZ" - end + (succ >> upcase).call('Ruby').should == "RUBZ" + end - it "calls passed Proc with arguments and then calls self with result" do - f = proc { |x| x * x } - g = proc { |x| x + x } + it "calls passed Proc with arguments and then calls self with result" do + f = proc { |x| x * x } + g = proc { |x| x + x } - (f >> g).call(2).should == 8 - (g >> f).call(2).should == 16 - end + (f >> g).call(2).should == 8 + (g >> f).call(2).should == 16 + end - it "accepts any callable object" do - inc = proc { |n| n + 1 } + it "accepts any callable object" do + inc = proc { |n| n + 1 } - double = Object.new - def double.call(n); n * 2; end + double = Object.new + def double.call(n); n * 2; end - (inc >> double).call(3).should == 8 - end + (inc >> double).call(3).should == 8 + end - it_behaves_like :proc_compose, :>>, -> { proc { |s| s.upcase } } + it_behaves_like :proc_compose, :>>, -> { proc { |s| s.upcase } } - describe "composition" do - it "is a Proc" do - f = proc { |x| x * x } - g = proc { |x| x + x } + describe "composition" do + it "is a Proc" do + f = proc { |x| x * x } + g = proc { |x| x + x } - (f >> g).is_a?(Proc).should == true - (f >> g).should_not.lambda? - end + (f >> g).is_a?(Proc).should == true + (f >> g).should_not.lambda? + end - it "is a Proc when other is lambda" do - f = proc { |x| x * x } - g = -> x { x + x } + it "is a Proc when other is lambda" do + f = proc { |x| x * x } + g = -> x { x + x } - (f >> g).is_a?(Proc).should == true - (f >> g).should_not.lambda? - end + (f >> g).is_a?(Proc).should == true + (f >> g).should_not.lambda? + end - it "is a lambda when self is lambda" do - f = -> x { x * x } - g = proc { |x| x + x } + it "is a lambda when self is lambda" do + f = -> x { x * x } + g = proc { |x| x + x } - (f >> g).is_a?(Proc).should == true - (f >> g).should.lambda? - end + (f >> g).is_a?(Proc).should == true + (f >> g).should.lambda? + end - it "may accept multiple arguments" do - inc = proc { |n| n + 1 } - mul = proc { |n, m| n * m } + it "may accept multiple arguments" do + inc = proc { |n| n + 1 } + mul = proc { |n, m| n * m } - (mul >> inc).call(2, 3).should == 7 - end + (mul >> inc).call(2, 3).should == 7 + end - it "passes blocks to the first proc" do - ScratchPad.record [] - one = proc { |&arg| arg.call :one if arg } - two = proc { |&arg| arg.call :two if arg } - (one >> two).call { |x| ScratchPad << x } - ScratchPad.recorded.should == [:one] - end + it "passes blocks to the first proc" do + ScratchPad.record [] + one = proc { |&arg| arg.call :one if arg } + two = proc { |&arg| arg.call :two if arg } + (one >> two).call { |x| ScratchPad << x } + ScratchPad.recorded.should == [:one] end end end diff --git a/spec/ruby/core/proc/shared/compose.rb b/spec/ruby/core/proc/shared/compose.rb index 64338cada8..e3ae7f76b8 100644 --- a/spec/ruby/core/proc/shared/compose.rb +++ b/spec/ruby/core/proc/shared/compose.rb @@ -1,5 +1,5 @@ describe :proc_compose, shared: true do - ruby_version_is "2.6"..."2.7" do + ruby_version_is ""..."2.7" do it "raises NoMethodError when called if passed not callable object" do not_callable = Object.new composed = @object.call.send(@method, not_callable) |