1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -3,7 +3,7 @@ require_relative '../../spec_helper'
describe "Proc#curry" do
before :each do
@proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) }
@lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) }
@lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) }
end
it "returns a Proc when called on a proc" do
@ -12,7 +12,7 @@ describe "Proc#curry" do
end
it "returns a Proc when called on a lambda" do
p = lambda { true }
p = -> { true }
p.curry.should be_an_instance_of(Proc)
end
@ -36,10 +36,10 @@ describe "Proc#curry" do
it "can be called multiple times on the same Proc" do
@proc_add.curry
lambda { @proc_add.curry }.should_not raise_error
-> { @proc_add.curry }.should_not raise_error
@lambda_add.curry
lambda { @lambda_add.curry }.should_not raise_error
-> { @lambda_add.curry }.should_not raise_error
end
it "can be passed superfluous arguments if created from a proc" do
@ -49,19 +49,19 @@ describe "Proc#curry" do
end
it "raises an ArgumentError if passed superfluous arguments when created from a lambda" do
lambda { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError)
lambda { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError)
-> { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError)
-> { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError)
end
it "returns Procs with arities of -1" do
@proc_add.curry.arity.should == -1
@lambda_add.curry.arity.should == -1
l = lambda { |*a| }
l = -> *a { }
l.curry.arity.should == -1
end
it "produces Procs that raise ArgumentError for #binding" do
lambda do
-> do
@proc_add.curry.binding
end.should raise_error(ArgumentError)
end
@ -81,7 +81,7 @@ describe "Proc#curry" do
end
it "combines arguments and calculates incoming arity accurately for successively currying" do
l = lambda{|a,b,c| a+b+c }
l = -> a, b, c { a+b+c }
l1 = l.curry.call(1)
# the l1 currying seems unnecessary, but it triggered the original issue
l2 = l1.curry.call(2)
@ -93,13 +93,13 @@ end
describe "Proc#curry with arity argument" do
before :each do
@proc_add = proc {|x,y,z| (x||0) + (y||0) + (z||0) }
@lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) }
@proc_add = proc { |x,y,z| (x||0) + (y||0) + (z||0) }
@lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) }
end
it "accepts an optional Integer argument for the arity" do
lambda { @proc_add.curry(3) }.should_not raise_error
lambda { @lambda_add.curry(3) }.should_not raise_error
-> { @proc_add.curry(3) }.should_not raise_error
-> { @lambda_add.curry(3) }.should_not raise_error
end
it "returns a Proc when called on a proc" do
@ -117,22 +117,22 @@ describe "Proc#curry with arity argument" do
end
it "raises an ArgumentError if called on a lambda that requires more than _arity_ arguments" do
lambda { @lambda_add.curry(2) }.should raise_error(ArgumentError)
lambda { lambda{|x, y, z, *more|}.curry(2) }.should raise_error(ArgumentError)
-> { @lambda_add.curry(2) }.should raise_error(ArgumentError)
-> { -> x, y, z, *more{}.curry(2) }.should raise_error(ArgumentError)
end
it 'returns a Proc if called on a lambda that requires fewer than _arity_ arguments but may take more' do
lambda{|a, b, c, d=nil, e=nil|}.curry(4).should be_an_instance_of(Proc)
lambda{|a, b, c, d=nil, *e|}.curry(4).should be_an_instance_of(Proc)
lambda{|a, b, c, *d|}.curry(4).should be_an_instance_of(Proc)
-> a, b, c, d=nil, e=nil {}.curry(4).should be_an_instance_of(Proc)
-> a, b, c, d=nil, *e {}.curry(4).should be_an_instance_of(Proc)
-> a, b, c, *d {}.curry(4).should be_an_instance_of(Proc)
end
it "raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments" do
lambda { @lambda_add.curry(4) }.should raise_error(ArgumentError)
lambda { lambda { true }.curry(1) }.should raise_error(ArgumentError)
lambda { lambda {|a, b=nil|}.curry(5) }.should raise_error(ArgumentError)
lambda { lambda {|a, &b|}.curry(2) }.should raise_error(ArgumentError)
lambda { lambda {|a, b=nil, &c|}.curry(3) }.should raise_error(ArgumentError)
-> { @lambda_add.curry(4) }.should raise_error(ArgumentError)
-> { -> { true }.curry(1) }.should raise_error(ArgumentError)
-> { -> a, b=nil {}.curry(5) }.should raise_error(ArgumentError)
-> { -> a, &b {}.curry(2) }.should raise_error(ArgumentError)
-> { -> a, b=nil, &c {}.curry(3) }.should raise_error(ArgumentError)
end
it "calls the curried proc with the arguments if _arity_ arguments have been given" do
@ -152,29 +152,29 @@ describe "Proc#curry with arity argument" do
it "can be specified multiple times on the same Proc" do
@proc_add.curry(2)
lambda { @proc_add.curry(1) }.should_not raise_error
-> { @proc_add.curry(1) }.should_not raise_error
@lambda_add.curry(3)
lambda { @lambda_add.curry(3) }.should_not raise_error
-> { @lambda_add.curry(3) }.should_not raise_error
end
it "can be passed more than _arity_ arguments if created from a proc" do
lambda { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not
-> { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not
raise_error(ArgumentError)
lambda { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not
-> { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not
raise_error(ArgumentError)
end
it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do
lambda { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError)
lambda { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError)
-> { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError)
-> { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError)
end
it "returns Procs with arities of -1 regardless of the value of _arity_" do
@proc_add.curry(1).arity.should == -1
@proc_add.curry(2).arity.should == -1
@lambda_add.curry(3).arity.should == -1
l = lambda { |*a| }
l = -> *a { }
l.curry(3).arity.should == -1
end
end