summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-23 16:03:15 -0700
committerJeremy Evans <code@jeremyevans.net>2020-03-22 09:30:07 -0700
commit4f7b435c955792af780fe9e94f98d3dde839e056 (patch)
treee6d3a5433aca7a48b79eba02056cc905dc3c88c4 /test
parent095e9f57af30fc286ba66557d86f080003ab6d5a (diff)
Support obj.clone(freeze: true) for freezing clone
This freezes the clone even if the receiver is not frozen. It is only for consistency with freeze: false not freezing the clone even if the receiver is frozen. Because Object#clone is now partially implemented in Ruby and not fully implemented in C, freeze: nil must be supported to provide the default behavior of only freezing the clone if the receiver is frozen. This requires modifying delegate and set, to set freeze: nil instead of freeze: true as the keyword parameter for initialize_clone. Those are the two libraries in stdlib that override initialize_clone. Implements [Feature #16175]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2969
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_object.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 55709bf3dc..3aa0a1b652 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -47,15 +47,27 @@ class TestObject < Test::Unit::TestCase
a = Object.new
def a.b; 2 end
+ c = a.clone
+ assert_equal(false, c.frozen?)
+ assert_equal(false, a.frozen?)
+ assert_equal(2, c.b)
+
+ c = a.clone(freeze: true)
+ assert_equal(true, c.frozen?)
+ assert_equal(false, a.frozen?)
+ assert_equal(2, c.b)
+
a.freeze
c = a.clone
assert_equal(true, c.frozen?)
+ assert_equal(true, a.frozen?)
assert_equal(2, c.b)
assert_raise(ArgumentError) {a.clone(freeze: [])}
d = a.clone(freeze: false)
def d.e; 3; end
assert_equal(false, d.frozen?)
+ assert_equal(true, a.frozen?)
assert_equal(2, d.b)
assert_equal(3, d.e)