Skip to content

Commit c176f9a

Browse files
committed
✅ Add basic test for SEARCH / UID SEARCH command
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.
1 parent 957efeb commit c176f9a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/net/imap/test_imap.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,30 @@ def test_unselect
12201220
end
12211221
end
12221222

1223+
test("#search/#uid_search") do
1224+
with_fake_server do |server, imap|
1225+
search_result = Net::IMAP::SearchResult[
1226+
1, 2, 3, 5, 8, 13, 21, 34, 55, modseq: 1234
1227+
]
1228+
search_resp = ->cmd do
1229+
cmd.puts search_result.to_s("SEARCH")
1230+
cmd.done_ok
1231+
end
1232+
1233+
server.on "SEARCH", &search_resp
1234+
assert_equal search_result, imap.search(["subject", "hello",
1235+
[1..5, 8, 10..-1]])
1236+
cmd = server.commands.pop
1237+
assert_equal ["SEARCH", "subject hello 1:5,8,10:*"], [cmd.name, cmd.args]
1238+
1239+
server.on "UID SEARCH", &search_resp
1240+
assert_equal search_result, imap.uid_search(["subject", "hello",
1241+
[1..22, 30..-1]])
1242+
cmd = server.commands.pop
1243+
assert_equal ["UID SEARCH", "subject hello 1:22,30:*"], [cmd.name, cmd.args]
1244+
end
1245+
end
1246+
12231247
test("missing server SEARCH response") do
12241248
with_fake_server do |server, imap|
12251249
server.on "SEARCH", &:done_ok

0 commit comments

Comments
 (0)