2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/common'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Proc#lambda?" do
|
|
|
|
it "returns true if the Proc was created from a block with the lambda keyword" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> {}.lambda?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if the Proc was created from a block with the proc keyword" do
|
|
|
|
proc {}.lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if the Proc was created from a block with Proc.new" do
|
|
|
|
Proc.new {}.lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is preserved when passing a Proc with & to the lambda keyword" do
|
2020-06-13 09:57:31 -04:00
|
|
|
suppress_warning {lambda(&->{})}.lambda?.should be_true
|
|
|
|
suppress_warning {lambda(&proc{})}.lambda?.should be_false
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is preserved when passing a Proc with & to the proc keyword" do
|
2019-07-27 06:40:09 -04:00
|
|
|
proc(&->{}).lambda?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
proc(&proc{}).lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is preserved when passing a Proc with & to Proc.new" do
|
2019-07-27 06:40:09 -04:00
|
|
|
Proc.new(&->{}).lambda?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
Proc.new(&proc{}).lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if the Proc was created from a block with &" do
|
|
|
|
ProcSpecs.new_proc_from_amp{}.lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is preserved when the Proc was passed using &" do
|
2019-07-27 06:40:09 -04:00
|
|
|
ProcSpecs.new_proc_from_amp(&->{}).lambda?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should be_false
|
|
|
|
ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true for a Method converted to a Proc" do
|
|
|
|
m = :foo.method(:to_s)
|
|
|
|
m.to_proc.lambda?.should be_true
|
|
|
|
ProcSpecs.new_proc_from_amp(&m).lambda?.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
# [ruby-core:24127]
|
|
|
|
it "is preserved when a Proc is curried" do
|
2019-07-27 06:40:09 -04:00
|
|
|
->{}.curry.lambda?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
proc{}.curry.lambda?.should be_false
|
|
|
|
Proc.new{}.curry.lambda?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is preserved when a curried Proc is called without enough arguments" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> x, y{}.curry.call(42).lambda?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
proc{|x,y|}.curry.call(42).lambda?.should be_false
|
|
|
|
Proc.new{|x,y|}.curry.call(42).lambda?.should be_false
|
|
|
|
end
|
|
|
|
end
|