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: 4 additions & 0 deletions lib/net/imap/sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ def valid_string
# Related: #valid_string, #normalized_string, #to_s
def string; @string ||= normalized_string if valid? end

# Returns an array with #normalized_string when valid and an empty array
# otherwise.
def deconstruct; valid? ? [normalized_string] : [] end

# Assigns a new string to #string and resets #elements to match. It
# cannot be set to an empty string—assign +nil+ or use #clear instead.
# The string is validated but not normalized.
Expand Down
12 changes: 12 additions & 0 deletions test/net/imap/test_sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,18 @@ def test_inspect((expected, input, freeze))
assert_equal str, set.string
end

test "#deconstruct" do |data|
set = SequenceSet.new(data[:input])
str = data[:normalize]
if str
assert_equal [str], set.deconstruct
set => SequenceSet[str]
else
assert_equal [], set.deconstruct
set => SequenceSet[]
end
end

test "#normalized_string" do |data|
set = SequenceSet.new(data[:input])
assert_equal data[:normalize], set.normalized_string
Expand Down