summaryrefslogtreecommitdiff
path: root/spec/ruby/language/hash_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-03-27 13:02:41 +0100
committerBenoit Daloze <eregontp@gmail.com>2021-03-27 13:02:41 +0100
commit95d9fe9538441eb57ee6752aa1c5088fc6608e34 (patch)
tree9a0bb070fd8042b83470f7a0bf9cd462c919c7c0 /spec/ruby/language/hash_spec.rb
parent44736a6b7a2b3475db2d05187f33e3c1a7b4b4e5 (diff)
Update to ruby/spec@fd6eddd
Diffstat (limited to 'spec/ruby/language/hash_spec.rb')
-rw-r--r--spec/ruby/language/hash_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb
index d6600ddb4a..afc0df12a2 100644
--- a/spec/ruby/language/hash_spec.rb
+++ b/spec/ruby/language/hash_spec.rb
@@ -167,3 +167,42 @@ describe "Hash literal" do
usascii_hash.keys.first.encoding.should == Encoding::US_ASCII
end
end
+
+describe "The ** operator" do
+ it "makes a copy when calling a method taking a keyword rest argument" do
+ def m(**h)
+ h.delete(:one); h
+ end
+
+ h = { one: 1, two: 2 }
+ m(**h).should == { two: 2 }
+ m(**h).should_not.equal?(h)
+ h.should == { one: 1, two: 2 }
+ end
+
+ ruby_version_is ""..."3.0" do
+ it "makes a caller-side copy when calling a method taking a positional Hash" do
+ def m(h)
+ h.delete(:one); h
+ end
+
+ h = { one: 1, two: 2 }
+ m(**h).should == { two: 2 }
+ m(**h).should_not.equal?(h)
+ h.should == { one: 1, two: 2 }
+ end
+ end
+
+ ruby_version_is "3.0" do
+ it "does not copy when calling a method taking a positional Hash" do
+ def m(h)
+ h.delete(:one); h
+ end
+
+ h = { one: 1, two: 2 }
+ m(**h).should == { two: 2 }
+ m(**h).should.equal?(h)
+ h.should == { two: 2 }
+ end
+ end
+end