Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Do not automatically freeze SearchResult #263

Merged
merged 1 commit into from
Feb 4, 2024
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
8 changes: 2 additions & 6 deletions lib/net/imap/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class IMAP
# For backward compatibility, SearchResult inherits from Array.
class SearchResult < Array

# Returns a frozen SearchResult populated with the given +seq_nums+.
# Returns a SearchResult populated with the given +seq_nums+.
#
# Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
# # => Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
Expand All @@ -22,19 +22,15 @@ def self.[](*seq_nums, modseq: nil)
# §3.1.6]}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.1.6].
attr_reader :modseq

# Returns a frozen SearchResult populated with the given +seq_nums+.
# Returns a SearchResult populated with the given +seq_nums+.
#
# Net::IMAP::SearchResult.new([1, 3, 5], modseq: 9)
# # => Net::IMAP::SearchResult[1, 3, 5, modseq: 9]
def initialize(seq_nums, modseq: nil)
super(seq_nums.to_ary.map { Integer _1 })
@modseq = Integer modseq if modseq
freeze
end

# Returns a frozen copy of +other+.
def initialize_copy(other); super; freeze end

# Returns whether +other+ is a SearchResult with the same values and the
# same #modseq. The order of numbers is irrelevant.
#
Expand Down
8 changes: 0 additions & 8 deletions test/net/imap/test_search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
class SearchDataTests < Test::Unit::TestCase
SearchResult = Net::IMAP::SearchResult

test "#frozen?" do
assert SearchResult.new([1, 3, 5]).frozen?
assert SearchResult[1, 3, 5].frozen?
assert SearchResult[1, 3, 5, modseq: 9].frozen?
assert SearchResult[1, 3, 5, modseq: 9].clone.frozen?
assert SearchResult[1, 3, 5, modseq: 9].dup.dup.frozen?
end

test "#modseq" do
assert_nil SearchResult[12, 34].modseq
assert_equal 123_456_789, SearchResult[12, 34, modseq: 123_456_789].modseq
Expand Down