Skip to content

Commit

Permalink
🐛 Fix Set inputs for SequenceSet
Browse files Browse the repository at this point in the history
This was broken by #319
  • Loading branch information
nevans committed Sep 26, 2024
1 parent cf7e62c commit 8c25109
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/net/imap/sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class IMAP
#
# SequenceSet.new may receive a single optional argument: a non-zero 32 bit
# unsigned integer, a range, a <tt>sequence-set</tt> formatted string,
# another sequence set, a Set (containing only numbers), or an Array
# containing any of these (array inputs may be nested).
# another sequence set, a Set (containing only numbers or <tt>*</tt>), or an
# Array containing any of these (array inputs may be nested).
#
# set = Net::IMAP::SequenceSet.new(1)
# set.valid_string #=> "1"
Expand Down Expand Up @@ -1265,7 +1265,7 @@ def input_to_tuples(obj)
when *STARS, Integer, Range then [input_to_tuple(obj)]
when String then str_to_tuples obj
when SequenceSet then obj.tuples
when Set then obj.map { to_tuple_int _1 }
when Set then obj.map { [to_tuple_int(_1)] * 2 }
when Array then obj.flat_map { input_to_tuples _1 }
when nil then []
else
Expand Down
14 changes: 14 additions & 0 deletions test/net/imap/test_sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def compare_to_reference_set(nums, set, seqset)
assert_empty SequenceSet.new [[]]
assert_empty SequenceSet.new nil
assert_empty SequenceSet.new ""
assert_empty SequenceSet.new Set.new
end

test ".[] must not be empty" do
Expand All @@ -148,6 +149,7 @@ def compare_to_reference_set(nums, set, seqset)
assert_raise DataFormatError do SequenceSet[[[]]] end
assert_raise DataFormatError do SequenceSet[nil] end
assert_raise DataFormatError do SequenceSet[""] end
assert_raise DataFormatError do SequenceSet[Set.new] end
end

test "#[non-negative index]" do
Expand Down Expand Up @@ -719,6 +721,18 @@ def test_inspect((expected, input, freeze))
complement: "6:8,12:98,100:#{2**32 - 1}",
}, keep: true

data "Set", {
input: Set[*(9..11), :*, 99, *(1..5)],
elements: [1..5, 9..11, 99, :*],
entries: [1..5, 9..11, 99, :*],
ranges: [1..5, 9..11, 99..99, :*..],
numbers: RangeError,
to_s: "1:5,9:11,99,*",
normalize: "1:5,9:11,99,*",
count: 10,
complement: "6:8,12:98,100:#{2**32 - 1}",
}, keep: true

data "empty", {
input: nil,
elements: [],
Expand Down

0 comments on commit 8c25109

Please sign in to comment.