Skip to content

Commit 26547e6

Browse files
committed
📖 Add new parser test doc, move uid_mapping test
1 parent 5fd9993 commit 26547e6

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
require "net/imap"
4+
require "test/unit"
5+
6+
class IMAPResponseDataTest < Test::Unit::TestCase
7+
8+
def setup
9+
@do_not_reverse_lookup = Socket.do_not_reverse_lookup
10+
Socket.do_not_reverse_lookup = true
11+
end
12+
13+
def teardown
14+
Socket.do_not_reverse_lookup = @do_not_reverse_lookup
15+
end
16+
17+
def test_uidplus_copyuid__uid_mapping
18+
parser = Net::IMAP::ResponseParser.new
19+
response = parser.parse(
20+
"A004 OK [copyUID 9999 20:19,500:495 92:97,101:100] Done\r\n"
21+
)
22+
code = response.data.code
23+
assert_equal(
24+
{
25+
19 => 92,
26+
20 => 93,
27+
495 => 94,
28+
496 => 95,
29+
497 => 96,
30+
498 => 97,
31+
499 => 100,
32+
500 => 101,
33+
},
34+
code.data.uid_mapping
35+
)
36+
end
37+
38+
end

test/net/imap/test_imap_response_parser.rb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def teardown
2323
# Tests that do no more than parse an example response and assert the result
2424
# data has the correct values have been moved to yml test fixtures.
2525
#
26-
# TODO: add instructions for how to quickly add or update yaml tests
26+
# The simplest way to add or update new test cases is to add only the test
27+
# name and response string to the yaml file, and then re-run the tests. The
28+
# test will be marked pending, and the parsed result will be serialized and
29+
# printed on stdout. This can then be copied into the yaml file.
2730
############################################################################
2831
# Core IMAP, by RFC9051 section (w/obsolete in relative RFC3501 section):
2932
generate_tests_from fixture_file: "rfc3501_examples.yml"
@@ -93,27 +96,4 @@ def teardown
9396
# response data, should still use normal tests, below
9497
############################################################################
9598

96-
# todo: move this to response data tests file
97-
# it's testing the mapping fn, not the parsing.
98-
def test_uidplus_copyuid__uid_mapping
99-
parser = Net::IMAP::ResponseParser.new
100-
response = parser.parse(
101-
"A004 OK [copyUID 9999 20:19,500:495 92:97,101:100] Done\r\n"
102-
)
103-
code = response.data.code
104-
assert_equal(
105-
{
106-
19 => 92,
107-
20 => 93,
108-
495 => 94,
109-
496 => 95,
110-
497 => 96,
111-
498 => 97,
112-
499 => 100,
113-
500 => 101,
114-
},
115-
code.data.uid_mapping
116-
)
117-
end
118-
11999
end

0 commit comments

Comments
 (0)