Skip to content

Commit

Permalink
πŸ”€ Merge pull request #392 from ruby/uidplus_data_test_coverage
Browse files Browse the repository at this point in the history
βœ… Improve UIDPlusData test coverage
  • Loading branch information
nevans authored Jan 31, 2025
2 parents a4f98ba + 3d52d84 commit d8d8428
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 58 deletions.
58 changes: 0 additions & 58 deletions test/net/imap/test_imap_response_data.rb

This file was deleted.

21 changes: 21 additions & 0 deletions test/net/imap/test_imap_response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,25 @@ def test_fetch_binary_and_binary_size
Net::IMAP.debug = debug
end

test "COPYUID with backwards ranges" do
parser = Net::IMAP::ResponseParser.new
response = parser.parse(
"A004 OK [copyUID 9999 20:19,500:495 92:97,101:100] Done\r\n"
)
code = response.data.code
assert_equal(
{
19 => 92,
20 => 93,
495 => 94,
496 => 95,
497 => 96,
498 => 97,
499 => 100,
500 => 101,
},
code.data.uid_mapping
)
end

end
27 changes: 27 additions & 0 deletions test/net/imap/test_thread_member.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "net/imap"
require "test/unit"

class ThreadMemberTest < Test::Unit::TestCase

test "#to_sequence_set" do
# copied from the fourth example in RFC5256: (3 6 (4 23)(44 7 96))
thmember = Net::IMAP::ThreadMember.method :new
thread = thmember.(3, [
thmember.(6, [
thmember.(4, [
thmember.(23, [])
]),
thmember.(44, [
thmember.(7, [
thmember.(96, [])
])
])
])
])
expected = Net::IMAP::SequenceSet.new("3:4,6:7,23,44,96")
assert_equal(expected, thread.to_sequence_set)
end

end
46 changes: 46 additions & 0 deletions test/net/imap/test_uid_plus_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require "net/imap"
require "test/unit"

class TestUIDPlusData < Test::Unit::TestCase

test "#uid_mapping with sorted source_uids" do
uidplus = Net::IMAP::UIDPlusData.new(
1, [19, 20, *(495..500)], [*(92..97), 100, 101],
)
assert_equal(
{
19 => 92,
20 => 93,
495 => 94,
496 => 95,
497 => 96,
498 => 97,
499 => 100,
500 => 101,
},
uidplus.uid_mapping
)
end

test "#uid_mapping for with source_uids in unsorted order" do
uidplus = Net::IMAP::UIDPlusData.new(
1, [*(495..500), 19, 20], [*(92..97), 100, 101],
)
assert_equal(
{
495 => 92,
496 => 93,
497 => 94,
498 => 95,
499 => 96,
500 => 97,
19 => 100,
20 => 101,
},
uidplus.uid_mapping
)
end

end

0 comments on commit d8d8428

Please sign in to comment.