diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-11-09 09:23:45 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2023-03-24 10:55:13 -0700 |
commit | d3197def882b47e7c57cdddfe8d62f62fef9d3f7 (patch) | |
tree | 52ab45b683bcc6e7f718dbdca1007d5a82928ed9 /spec | |
parent | 35e9b5348d91eff13d2bdc487003f46a19586d42 (diff) | |
download | ruby-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.rb | 18 |
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 |