summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2022-11-09 09:23:45 -0800
committerJeremy Evans <code@jeremyevans.net>2023-03-24 10:55:13 -0700
commitd3197def882b47e7c57cdddfe8d62f62fef9d3f7 (patch)
tree52ab45b683bcc6e7f718dbdca1007d5a82928ed9 /spec
parent35e9b5348d91eff13d2bdc487003f46a19586d42 (diff)
downloadruby-d3197def882b47e7c57cdddfe8d62f62fef9d3f7.tar.gz
Do not copy compare_by_identity flag for non-empty hashes in Hash.[]
It wasn't copied for empty hashes, and Hash.[] doesn't copy the default value, so copying the compare_by_identity flag does not make sense. Partially Fixes [Bug #19113]
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/hash/constructor_spec.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb
index 8fba47958f..8d29773909 100644
--- a/spec/ruby/core/hash/constructor_spec.rb
+++ b/spec/ruby/core/hash/constructor_spec.rb
@@ -103,8 +103,26 @@ describe "Hash.[]" do
HashSpecs::MyInitializerHash[Hash[1, 2]].should be_an_instance_of(HashSpecs::MyInitializerHash)
end
+ it "removes the default value" do
+ hash = Hash.new(1)
+ Hash[hash].default.should be_nil
+ hash[:a] = 1
+ Hash[hash].default.should be_nil
+ end
+
it "removes the default_proc" do
hash = Hash.new { |h, k| h[k] = [] }
Hash[hash].default_proc.should be_nil
+ hash[:a] = 1
+ Hash[hash].default_proc.should be_nil
+ end
+
+ ruby_version_is '3.3' do
+ it "does not retain compare_by_identity_flag" do
+ hash = {}.compare_by_identity
+ Hash[hash].compare_by_identity?.should == false
+ hash[:a] = 1
+ Hash[hash].compare_by_identity?.should == false
+ end
end
end