summaryrefslogtreecommitdiff
path: root/spec/ruby/core/proc
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-06-01 12:28:05 -0700
committerJeremy Evans <code@jeremyevans.net>2020-06-19 12:58:25 -0700
commit878af5147def7fed089d3cc388742f0111db58ae (patch)
tree93e6e68b6b40575f7a1f3a641383c4111f05ef08 /spec/ruby/core/proc
parentb3aff6a11cbc96e5fc6c615d3f7a7a11fda6f59a (diff)
Implement Proc#== and #eql?
Previously, these were not implemented, and Object#== and #eql? were used. This tries to check the proc internals to make sure that procs created from separate blocks are treated as not equal, but procs created from the same block are treated as equal, even when the lazy proc allocation optimization is used. Implements [Feature #14267]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3174
Diffstat (limited to 'spec/ruby/core/proc')
-rw-r--r--spec/ruby/core/proc/eql_spec.rb8
-rw-r--r--spec/ruby/core/proc/equal_value_spec.rb8
-rw-r--r--spec/ruby/core/proc/shared/equal.rb14
3 files changed, 21 insertions, 9 deletions
diff --git a/spec/ruby/core/proc/eql_spec.rb b/spec/ruby/core/proc/eql_spec.rb
index a3c5a5658d..d95e890c29 100644
--- a/spec/ruby/core/proc/eql_spec.rb
+++ b/spec/ruby/core/proc/eql_spec.rb
@@ -2,5 +2,11 @@ require_relative '../../spec_helper'
require_relative 'shared/equal'
describe "Proc#eql?" do
- it_behaves_like :proc_equal_undefined, :eql?
+ ruby_version_is "0"..."2.8" do
+ it_behaves_like :proc_equal_undefined, :eql?
+ end
+
+ ruby_version_is "2.8" do
+ it_behaves_like :proc_equal, :eql?
+ end
end
diff --git a/spec/ruby/core/proc/equal_value_spec.rb b/spec/ruby/core/proc/equal_value_spec.rb
index 1b6ac792cf..fb465992e9 100644
--- a/spec/ruby/core/proc/equal_value_spec.rb
+++ b/spec/ruby/core/proc/equal_value_spec.rb
@@ -2,5 +2,11 @@ require_relative '../../spec_helper'
require_relative 'shared/equal'
describe "Proc#==" do
- it_behaves_like :proc_equal_undefined, :==
+ ruby_version_is "0"..."2.8" do
+ it_behaves_like :proc_equal_undefined, :==
+ end
+
+ ruby_version_is "2.8" do
+ it_behaves_like :proc_equal, :==
+ end
end
diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb
index 46a1894424..0c0020ca7f 100644
--- a/spec/ruby/core/proc/shared/equal.rb
+++ b/spec/ruby/core/proc/shared/equal.rb
@@ -36,26 +36,26 @@ describe :proc_equal, shared: true do
a.send(@method, b).should be_false
end
- it "returns true if both procs have the same body and environment" do
+ it "returns false if procs are distinct but have the same body and environment" do
p = proc { :foo }
p2 = proc { :foo }
- p.send(@method, p2).should be_true
+ p.send(@method, p2).should be_false
end
- it "returns true if both lambdas with the same body and environment" do
+ it "returns false if lambdas are distinct but have same body and environment" do
x = -> { :foo }
x2 = -> { :foo }
- x.send(@method, x2).should be_true
+ x.send(@method, x2).should be_false
end
- it "returns true if both different kinds of procs with the same body and env" do
+ it "returns false if using comparing lambda to proc, even with the same body and env" do
p = -> { :foo }
p2 = proc { :foo }
- p.send(@method, p2).should be_true
+ p.send(@method, p2).should be_false
x = proc { :bar }
x2 = -> { :bar }
- x.send(@method, x2).should be_true
+ x.send(@method, x2).should be_false
end
it "returns false if other is not a Proc" do