Skip to content

Commit 24c5639

Browse files
committed
♻️ Move most UIDPLUS parse test to yaml
1 parent 2b12e0e commit 24c5639

File tree

2 files changed

+92
-53
lines changed

2 files changed

+92
-53
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
:tests:
3+
test_uidplus_appenduid:
4+
:response: "A003 OK [APPENDUID 38505 3955] APPEND completed\r\n"
5+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
6+
tag: A003
7+
name: OK
8+
data: !ruby/struct:Net::IMAP::ResponseText
9+
code: !ruby/struct:Net::IMAP::ResponseCode
10+
name: APPENDUID
11+
data: !ruby/struct:Net::IMAP::UIDPlusData
12+
uidvalidity: 38505
13+
source_uids:
14+
assigned_uids:
15+
- 3955
16+
text: APPEND completed
17+
raw_data: "A003 OK [APPENDUID 38505 3955] APPEND completed\r\n"
18+
test_uidplus_appenduid_multiappend_compatibility:
19+
:response: "A003 OK [APPENDUID 2 4,6:7,9] APPEND completed\r\n"
20+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
21+
tag: A003
22+
name: OK
23+
data: !ruby/struct:Net::IMAP::ResponseText
24+
code: !ruby/struct:Net::IMAP::ResponseCode
25+
name: APPENDUID
26+
data: !ruby/struct:Net::IMAP::UIDPlusData
27+
uidvalidity: 2
28+
source_uids:
29+
assigned_uids:
30+
- 4
31+
- 6
32+
- 7
33+
- 9
34+
text: APPEND completed
35+
raw_data: "A003 OK [APPENDUID 2 4,6:7,9] APPEND completed\r\n"
36+
test_uidplus_copyuid_rfc4315_example_with_mixed_case:
37+
:response: "A004 OK [copyUID 38505 304,319:320 3956:3958] Done\r\n"
38+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
39+
tag: A004
40+
name: OK
41+
data: !ruby/struct:Net::IMAP::ResponseText
42+
code: !ruby/struct:Net::IMAP::ResponseCode
43+
name: COPYUID
44+
data: !ruby/struct:Net::IMAP::UIDPlusData
45+
uidvalidity: 38505
46+
source_uids:
47+
- 304
48+
- 319
49+
- 320
50+
assigned_uids:
51+
- 3956
52+
- 3957
53+
- 3958
54+
text: Done
55+
raw_data: "A004 OK [copyUID 38505 304,319:320 3956:3958] Done\r\n"
56+
test_uidplus_copyuid_with_reversed_ranges:
57+
comment: |
58+
From RFC4315 ABNF:
59+
> and all values between these two *regardless of order*.
60+
> Example: 2:4 and 4:2 are equivalent.
61+
:response: "A004 OK [copyUID 9999 20:19,500:495 92:97,101:100] Done\r\n"
62+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
63+
tag: A004
64+
name: OK
65+
data: !ruby/struct:Net::IMAP::ResponseText
66+
code: !ruby/struct:Net::IMAP::ResponseCode
67+
name: COPYUID
68+
data: !ruby/struct:Net::IMAP::UIDPlusData
69+
uidvalidity: 9999
70+
source_uids:
71+
- 19
72+
- 20
73+
- 495
74+
- 496
75+
- 497
76+
- 498
77+
- 499
78+
- 500
79+
assigned_uids:
80+
- 92
81+
- 93
82+
- 94
83+
- 95
84+
- 96
85+
- 97
86+
- 100
87+
- 101
88+
text: Done
89+
raw_data: "A004 OK [copyUID 9999 20:19,500:495 92:97,101:100] Done\r\n"

test/net/imap/test_imap_response_parser.rb

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def teardown
4242
############################################################################
4343
# IMAP extensions, by RFC:
4444

45+
# RFC 4315: UIDPLUS extension, APPENDUID and COPYUID response codes
46+
generate_tests_from fixture_file: "uidplus_extension.yml"
47+
4548
# RFC 5256: THREAD response
4649
generate_tests_from fixture_file: "thread_responses.yml"
4750

@@ -208,59 +211,6 @@ def test_ignored_response
208211
assert_instance_of(Net::IMAP::IgnoredResponse, response)
209212
end
210213

211-
def test_uidplus_appenduid
212-
parser = Net::IMAP::ResponseParser.new
213-
# RFC4315 example
214-
response = parser.parse(
215-
"A003 OK [APPENDUID 38505 3955] APPEND completed\r\n"
216-
)
217-
code = response.data.code
218-
assert_equal "APPENDUID", code.name
219-
assert_kind_of Net::IMAP::UIDPlusData, code.data
220-
assert_equal Net::IMAP::UIDPlusData.new(38505, nil, [3955]), code.data
221-
assert_equal "APPENDUID", code.name
222-
assert_kind_of Net::IMAP::UIDPlusData, code.data
223-
assert_equal Net::IMAP::UIDPlusData.new(38505, nil, [3955]), code.data
224-
# MULTIAPPEND compatibility:
225-
response = parser.parse(
226-
"A003 OK [APPENDUID 2 4,6:7,9] APPEND completed\r\n"
227-
)
228-
code = response.data.code
229-
assert_equal "APPENDUID", code.name
230-
assert_kind_of Net::IMAP::UIDPlusData, code.data
231-
assert_equal Net::IMAP::UIDPlusData.new(2, nil, [4, 6, 7, 9]), code.data
232-
end
233-
234-
def test_uidplus_copyuid
235-
parser = Net::IMAP::ResponseParser.new
236-
# RFC4315 example, but using mixed case "copyUID".
237-
response = parser.parse(
238-
"A004 OK [copyUID 38505 304,319:320 3956:3958] Done\r\n"
239-
)
240-
code = response.data.code
241-
assert_equal "COPYUID", code.name
242-
assert_kind_of Net::IMAP::UIDPlusData, code.data
243-
assert_equal Net::IMAP::UIDPlusData.new(
244-
38505, [304, 319, 320], [3956, 3957, 3958]
245-
), code.data
246-
end
247-
248-
# From RFC4315 ABNF:
249-
# > and all values between these two *regardless of order*.
250-
# > Example: 2:4 and 4:2 are equivalent.
251-
def test_uidplus_copyuid__reversed_ranges
252-
parser = Net::IMAP::ResponseParser.new
253-
response = parser.parse(
254-
"A004 OK [copyUID 9999 20:19,500:495 92:97,101:100] Done\r\n"
255-
)
256-
code = response.data.code
257-
assert_equal Net::IMAP::UIDPlusData.new(
258-
9999,
259-
[19, 20, 495, 496, 497, 498, 499, 500],
260-
[92, 93, 94, 95, 96, 97, 100, 101]
261-
), code.data
262-
end
263-
264214
def test_uidplus_copyuid__uid_mapping
265215
parser = Net::IMAP::ResponseParser.new
266216
response = parser.parse(

0 commit comments

Comments
 (0)