diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-11-09 09:37:04 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2023-03-24 10:55:13 -0700 |
commit | 1b13db25d8ed0f328acc4e86668f8ad7deae7221 (patch) | |
tree | f642a812e98c7c749bacb3be101205e179194bfc /spec | |
parent | d3197def882b47e7c57cdddfe8d62f62fef9d3f7 (diff) | |
download | ruby-1b13db25d8ed0f328acc4e86668f8ad7deae7221.tar.gz |
Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hash
This was already copied for non-empty hashes. As Hash.ruby2_keywords_hash
copies default values, it should also copy the compare_by_identity flag.
Partially Fixes [Bug #19113]
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/hash/ruby2_keywords_hash_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb index e9337b9d1c..7dbb9c0a98 100644 --- a/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb +++ b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb @@ -56,4 +56,28 @@ describe "Hash.ruby2_keywords_hash" do it "raises TypeError for non-Hash" do -> { Hash.ruby2_keywords_hash(nil) }.should raise_error(TypeError) end + + it "retains the default value" do + hash = Hash.new(1) + Hash.ruby2_keywords_hash(hash).default.should == 1 + hash[:a] = 1 + Hash.ruby2_keywords_hash(hash).default.should == 1 + end + + it "retains the default_proc" do + pr = proc { |h, k| h[k] = [] } + hash = Hash.new(&pr) + Hash.ruby2_keywords_hash(hash).default_proc.should == pr + hash[:a] = 1 + Hash.ruby2_keywords_hash(hash).default_proc.should == pr + end + + ruby_version_is '3.3' do + it "retains compare_by_identity_flag" do + hash = {}.compare_by_identity + Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true + hash[:a] = 1 + Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true + end + end end |