Skip to content

Commit 0f84982

Browse files
committed
♻️ Move SEARCH response parser tests to yaml
🚧 Tests for modseq on SearchResult were commented out for now. That PR is coming soon. :)
1 parent 24db9c8 commit 0f84982

File tree

2 files changed

+80
-37
lines changed

2 files changed

+80
-37
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
:tests:
3+
test_search_response_empty:
4+
:response: "* SEARCH\r\n"
5+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
6+
name: SEARCH
7+
data: []
8+
# data: !ruby/array:Net::IMAP::SearchResult
9+
# internal: []
10+
# ivars:
11+
# "@modseq":
12+
raw_data: "* SEARCH\r\n"
13+
14+
test_search_response_single_seq_nums_returned:
15+
:response: "* SEARCH 1\r\n"
16+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
17+
name: SEARCH
18+
data: # !ruby/array:Net::IMAP::SearchResult
19+
# internal:
20+
- 1
21+
# ivars:
22+
# "@modseq":
23+
raw_data: "* SEARCH 1\r\n"
24+
25+
test_search_response_multiple_seq_nums_returned:
26+
:response: "* SEARCH 1 2 3\r\n"
27+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
28+
name: SEARCH
29+
data: # !ruby/array:Net::IMAP::SearchResult
30+
# internal:
31+
- 1
32+
- 2
33+
- 3
34+
# ivars:
35+
# "@modseq":
36+
raw_data: "* SEARCH 1 2 3\r\n"
37+
38+
test_invalid_search_response_single_result_with_trailing_space:
39+
:quirky_servers: Yahoo
40+
:response: "* SEARCH 1 \r\n"
41+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
42+
name: SEARCH
43+
data: # !ruby/array:Net::IMAP::SearchResult
44+
# internal:
45+
- 1
46+
# ivars:
47+
# "@modseq":
48+
raw_data: "* SEARCH 1 \r\n"
49+
50+
test_invalid_search_response_multiple_result_with_trailing_space:
51+
:quirky_servers: Yahoo
52+
:response: "* SEARCH 1 2 3 \r\n"
53+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
54+
name: SEARCH
55+
data: # !ruby/array:Net::IMAP::SearchResult
56+
# internal:
57+
- 1
58+
- 2
59+
- 3
60+
# ivars:
61+
# "@modseq":
62+
raw_data: "* SEARCH 1 2 3 \r\n"
63+
64+
test_search_response_with_condstore_modseq:
65+
:comment: |
66+
[Bug #10112]
67+
:response: "* SEARCH 87216 87221 (MODSEQ 7667567)\r\n"
68+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
69+
name: SEARCH
70+
data: # !ruby/array:Net::IMAP::SearchResult
71+
# internal:
72+
- 87216
73+
- 87221
74+
# ivars:
75+
# "@modseq": 7667567
76+
raw_data: "* SEARCH 87216 87221 (MODSEQ 7667567)\r\n"

test/net/imap/test_imap_response_parser.rb

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ def teardown
2525
#
2626
# TODO: add instructions for how to quickly add or update yaml tests
2727
############################################################################
28-
# Core IMAP specs, by RFC9051 section (w/ obsolete listed last):
28+
# Core IMAP, by RFC9051 section (w/obsolete in relative RFC3501 section):
2929

3030
# §7.3.2: NAMESPACE response (also RFC2342)
3131
generate_tests_from fixture_file: "namespace_responses.yml"
3232

33+
# RFC3501 §7.2.5: SEARCH response (obsolete in IMAP4rev2):
34+
generate_tests_from fixture_file: "search_responses.yml"
35+
3336
# §7.5.2: FETCH response, BODYSTRUCTURE msg-att
3437
generate_tests_from fixture_file: "body_structure_responses.yml"
3538

@@ -68,34 +71,6 @@ def test_resp_text_code
6871
assert_equal "CLOSED", response.data.code.name
6972
end
7073

71-
def test_search_response
72-
parser = Net::IMAP::ResponseParser.new
73-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
74-
* SEARCH
75-
EOF
76-
assert_equal [], response.data
77-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
78-
* SEARCH 1
79-
EOF
80-
assert_equal [1], response.data
81-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
82-
* SEARCH 1 2 3
83-
EOF
84-
assert_equal [1, 2, 3], response.data
85-
end
86-
87-
def test_search_response_of_yahoo
88-
parser = Net::IMAP::ResponseParser.new
89-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
90-
* SEARCH 1\s
91-
EOF
92-
assert_equal [1], response.data
93-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
94-
* SEARCH 1 2 3\s
95-
EOF
96-
assert_equal [1, 2, 3], response.data
97-
end
98-
9974
def test_msg_att_extra_space
10075
parser = Net::IMAP::ResponseParser.new
10176
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
@@ -194,14 +169,6 @@ def test_id
194169
assert_equal(nil, response.data.fetch("support-url"))
195170
end
196171

197-
# [Bug #10112]
198-
def test_search_modseq
199-
parser = Net::IMAP::ResponseParser.new
200-
response = parser.parse("* SEARCH 87216 87221 (MODSEQ 7667567)\r\n")
201-
assert_equal("SEARCH", response.name)
202-
assert_equal([87216, 87221], response.data)
203-
end
204-
205172
# [Bug #13649]
206173
def test_status
207174
parser = Net::IMAP::ResponseParser.new

0 commit comments

Comments
 (0)