diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/proc/lambda_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/proc/lambda_spec.rb')
-rw-r--r-- | spec/ruby/core/proc/lambda_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/ruby/core/proc/lambda_spec.rb b/spec/ruby/core/proc/lambda_spec.rb new file mode 100644 index 0000000000..33c9ebdd55 --- /dev/null +++ b/spec/ruby/core/proc/lambda_spec.rb @@ -0,0 +1,60 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/common', __FILE__) + +describe "Proc#lambda?" do + it "returns true if the Proc was created from a block with the lambda keyword" do + lambda {}.lambda?.should be_true + 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 + lambda(&lambda{}).lambda?.should be_true + lambda(&proc{}).lambda?.should be_false + end + + it "is preserved when passing a Proc with & to the proc keyword" do + proc(&lambda{}).lambda?.should be_true + proc(&proc{}).lambda?.should be_false + end + + it "is preserved when passing a Proc with & to Proc.new" do + Proc.new(&lambda{}).lambda?.should be_true + 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 + ProcSpecs.new_proc_from_amp(&lambda{}).lambda?.should be_true + 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 + lambda{}.curry.lambda?.should be_true + 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 + lambda{|x,y|}.curry.call(42).lambda?.should be_true + proc{|x,y|}.curry.call(42).lambda?.should be_false + Proc.new{|x,y|}.curry.call(42).lambda?.should be_false + end +end |