Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/net/imap/config/attr_accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def freeze

private

def initialize_clone(other)
def initialize_clone(other, **kwargs)
super
@data = other.data.clone
@data = other.data.clone(**kwargs)
end

def initialize_dup(other)
Expand Down
5 changes: 3 additions & 2 deletions lib/net/imap/sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1869,8 +1869,9 @@ def remain_frozen(set) frozen? ? set.freeze : set end
def remain_frozen_empty; frozen? ? SequenceSet.empty : SequenceSet.new end

# frozen clones are shallow copied
def initialize_clone(other)
@set_data = other.dup_set_data unless other.frozen?
def initialize_clone(other, freeze: nil)
@set_data = other.dup_set_data unless other.frozen? && freeze != false
freeze_set_data if freeze
super
end

Expand Down
15 changes: 15 additions & 0 deletions test/net/imap/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ def duck.to_r = 1/11111
assert_equal 1, copy.open_timeout
end

test "#clone(freeze:)" do
original = Config.new(open_timeout: 1).freeze
copy = original.clone(freeze: false)
refute copy.frozen?
copy.open_timeout = 2
assert_equal 1, original.open_timeout
assert_equal 2, copy.open_timeout

copy = Config.new(open_timeout: 1).clone(freeze: true)
assert copy.frozen?
assert_raise FrozenError do
copy.open_timeout = 2
end
end

test "#inherited? and #reset" do
base = Config.new debug: false, open_timeout: 99, idle_response_timeout: 15
child = base.new debug: true, open_timeout: 15, idle_response_timeout: 10
Expand Down
15 changes: 15 additions & 0 deletions test/net/imap/test_sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ def compare_to_reference_set(nums, set, seqset)
end
end

test "#clone(freeze:)" do
original = SequenceSet["2:4,7:11,99,999"]
copy = original.clone(freeze: false)
refute copy.frozen?
copy << 123
assert copy.include?(123)
assert !original.include?(123)

copy = SequenceSet.new("2:4,7:11,99,999").clone(freeze: true)
assert copy.frozen?
assert_raise FrozenError do
copy << 123
end
end

if defined?(Ractor)
test "#freeze makes ractor sharable (deeply frozen)" do
assert Ractor.shareable? SequenceSet.new("1:9,99,999").freeze
Expand Down