Skip to content

Commit

Permalink
✅ Add basic test for SEARCH / UID SEARCH command
Browse files Browse the repository at this point in the history
I've been working on a validating search syntax, so we can eventually
deprecate all automatic usage of RawData.  There will be a much bigger
test suite for that change.  But the full stack test (using FakeServer)
doesn't need much more than this.
  • Loading branch information
nevans committed Feb 4, 2024
1 parent 957efeb commit c176f9a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,30 @@ def test_unselect
end
end

test("#search/#uid_search") do
with_fake_server do |server, imap|
search_result = Net::IMAP::SearchResult[
1, 2, 3, 5, 8, 13, 21, 34, 55, modseq: 1234
]
search_resp = ->cmd do
cmd.puts search_result.to_s("SEARCH")
cmd.done_ok
end

server.on "SEARCH", &search_resp
assert_equal search_result, imap.search(["subject", "hello",
[1..5, 8, 10..-1]])
cmd = server.commands.pop
assert_equal ["SEARCH", "subject hello 1:5,8,10:*"], [cmd.name, cmd.args]

server.on "UID SEARCH", &search_resp
assert_equal search_result, imap.uid_search(["subject", "hello",
[1..22, 30..-1]])
cmd = server.commands.pop
assert_equal ["UID SEARCH", "subject hello 1:22,30:*"], [cmd.name, cmd.args]
end
end

test("missing server SEARCH response") do
with_fake_server do |server, imap|
server.on "SEARCH", &:done_ok
Expand Down

0 comments on commit c176f9a

Please sign in to comment.