Skip to content

Commit c94d92d

Browse files
committed
♻️ Move resp-text response parser tests to yaml
1 parent 9e1298d commit c94d92d

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
:tests:
3+
test_resp_text_with_code:
4+
:response: "* OK [CLOSED] Previous mailbox closed.\r\n"
5+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
6+
name: OK
7+
data: !ruby/struct:Net::IMAP::ResponseText
8+
code: !ruby/struct:Net::IMAP::ResponseCode
9+
name: CLOSED
10+
data:
11+
text: Previous mailbox closed.
12+
raw_data: "* OK [CLOSED] Previous mailbox closed.\r\n"
13+
14+
test_resp_text_with_T_LBRA:
15+
:response: "RUBY0004 OK [READ-WRITE] [Gmail]/Sent Mail selected. (Success)\r\n"
16+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
17+
tag: RUBY0004
18+
name: OK
19+
data: !ruby/struct:Net::IMAP::ResponseText
20+
code: !ruby/struct:Net::IMAP::ResponseCode
21+
name: READ-WRITE
22+
data:
23+
text: "[Gmail]/Sent Mail selected. (Success)"
24+
raw_data: "RUBY0004 OK [READ-WRITE] [Gmail]/Sent Mail selected. (Success)\r\n"
25+
26+
test_resp_text_with_BADCHARSET_astrings:
27+
:response: "t BAD [BADCHARSET (US-ASCII \"[astring with brackets]\")] unsupported
28+
charset foo.\r\n"
29+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
30+
tag: t
31+
name: BAD
32+
data: !ruby/struct:Net::IMAP::ResponseText
33+
code: !ruby/struct:Net::IMAP::ResponseCode
34+
name: BADCHARSET
35+
data:
36+
- US-ASCII
37+
- "[astring with brackets]"
38+
text: unsupported charset foo.
39+
raw_data: "t BAD [BADCHARSET (US-ASCII \"[astring with brackets]\")] unsupported
40+
charset foo.\r\n"

test/net/imap/test_imap_response_parser.rb

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def teardown
2727
############################################################################
2828
# Core IMAP, by RFC9051 section (w/obsolete in relative RFC3501 section):
2929

30+
# §7.1: Generic Status Responses (OK, NO, BAD, PREAUTH, BYE, codes, text)
31+
generate_tests_from fixture_file: "resp_text_responses.yml"
32+
3033
# §7.2.2: CAPABILITY response
3134
generate_tests_from fixture_file: "capability_responses.yml"
3235

@@ -78,14 +81,6 @@ def test_flag_xlist_inbox
7881
assert_equal [:Inbox], response.data.attr
7982
end
8083

81-
def test_resp_text_code
82-
parser = Net::IMAP::ResponseParser.new
83-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
84-
* OK [CLOSED] Previous mailbox closed.
85-
EOF
86-
assert_equal "CLOSED", response.data.code.name
87-
end
88-
8984
def test_msg_att_extra_space
9085
parser = Net::IMAP::ResponseParser.new
9186
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
@@ -158,22 +153,6 @@ def test_msg_att_modseq_data
158153
assert_equal(12345, response.data.attr["MODSEQ"])
159154
end
160155

161-
def test_msg_rfc3501_response_text_with_T_LBRA
162-
parser = Net::IMAP::ResponseParser.new
163-
response = parser.parse("RUBY0004 OK [READ-WRITE] [Gmail]/Sent Mail selected. (Success)\r\n")
164-
assert_equal("RUBY0004", response.tag)
165-
assert_equal("READ-WRITE", response.data.code.name)
166-
assert_equal("[Gmail]/Sent Mail selected. (Success)", response.data.text)
167-
end
168-
169-
def test_msg_rfc3501_response_text_with_BADCHARSET_astrings
170-
parser = Net::IMAP::ResponseParser.new
171-
response = parser.parse("t BAD [BADCHARSET (US-ASCII \"[astring with brackets]\")] unsupported charset foo.\r\n")
172-
assert_equal("t", response.tag)
173-
assert_equal("unsupported charset foo.", response.data.text)
174-
assert_equal("BADCHARSET", response.data.code.name)
175-
end
176-
177156
def test_continuation_request_without_response_text
178157
parser = Net::IMAP::ResponseParser.new
179158
response = parser.parse("+\r\n")

0 commit comments

Comments
 (0)