Skip to content

Commit e97bc8d

Browse files
committed
✅ Move NAMESPACE parser tests to yml and add more
1 parent 8d5f2ad commit e97bc8d

File tree

2 files changed

+180
-32
lines changed

2 files changed

+180
-32
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
:tests:
3+
4+
# The same examples are used by RFC9051 §6.3.10
5+
NAMESPACE_rfc2342_example_5.1:
6+
:response: &rfc2342_ex5_1 "* NAMESPACE ((\"\" \"/\")) NIL NIL\r\n"
7+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
8+
name: NAMESPACE
9+
data: !ruby/struct:Net::IMAP::Namespaces
10+
personal:
11+
- !ruby/struct:Net::IMAP::Namespace
12+
prefix: ''
13+
delim: "/"
14+
extensions: {}
15+
other: []
16+
shared: []
17+
raw_data: *rfc2342_ex5_1
18+
19+
NAMESPACE_rfc2342_example_5.2:
20+
:response: &rfc2342_ex5_2 "* NAMESPACE NIL NIL ((\"\" \".\"))\r\n"
21+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
22+
name: NAMESPACE
23+
data: !ruby/struct:Net::IMAP::Namespaces
24+
personal: []
25+
other: []
26+
shared:
27+
- !ruby/struct:Net::IMAP::Namespace
28+
prefix: ''
29+
delim: "."
30+
extensions: {}
31+
raw_data: *rfc2342_ex5_2
32+
33+
NAMESPACE_rfc2342_example_5.3:
34+
:response: &rfc2342_ex5_3 "* NAMESPACE ((\"\" \"/\")) NIL ((\"Public Folders/\" \"/\"))\r\n"
35+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
36+
name: NAMESPACE
37+
data: !ruby/struct:Net::IMAP::Namespaces
38+
personal:
39+
- !ruby/struct:Net::IMAP::Namespace
40+
prefix: ''
41+
delim: "/"
42+
extensions: {}
43+
other: []
44+
shared:
45+
- !ruby/struct:Net::IMAP::Namespace
46+
prefix: Public Folders/
47+
delim: "/"
48+
extensions: {}
49+
raw_data: *rfc2342_ex5_3
50+
51+
NAMESPACE_rfc2342_example_5.4:
52+
# WARNING: this example is wrong and will be fixed soon...
53+
:response: &rfc2342_ex5_4 "* NAMESPACE ((\"\" \"/\")) ((\"~\" \"/\")) ((\"#shared/\" \"/\") (\"#public/\"
54+
\"/\") (\"#ftp/\" \"/\") (\"#news.\" \".\"))\r\n"
55+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
56+
name: NAMESPACE
57+
data: !ruby/struct:Net::IMAP::Namespaces
58+
personal:
59+
- !ruby/struct:Net::IMAP::Namespace
60+
prefix: ''
61+
delim: "/"
62+
extensions: {}
63+
other:
64+
- !ruby/struct:Net::IMAP::Namespace
65+
prefix: "~"
66+
delim: "/"
67+
extensions: {}
68+
shared:
69+
- !ruby/struct:Net::IMAP::Namespace
70+
prefix: "#shared/"
71+
delim: "/"
72+
extensions: {}
73+
- !ruby/struct:Net::IMAP::Namespace
74+
prefix: "#public/"
75+
delim: "/"
76+
extensions: {}
77+
- !ruby/struct:Net::IMAP::Namespace
78+
prefix: "#ftp/"
79+
delim: "/"
80+
extensions: {}
81+
- !ruby/struct:Net::IMAP::Namespace
82+
prefix: "#news."
83+
delim: "."
84+
extensions: {}
85+
raw_data: *rfc2342_ex5_4
86+
87+
NAMESPACE_rfc2342_example_5.5:
88+
# FYI: it looks like both RFCs contain an extra SP char in this example
89+
:response: &rfc2342_ex5_5 "* NAMESPACE ((\"INBOX.\" \".\")) NIL NIL\r\n"
90+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
91+
name: NAMESPACE
92+
data: !ruby/struct:Net::IMAP::Namespaces
93+
personal:
94+
- !ruby/struct:Net::IMAP::Namespace
95+
prefix: INBOX.
96+
delim: "."
97+
extensions: {}
98+
other: []
99+
shared: []
100+
raw_data: *rfc2342_ex5_5
101+
102+
NAMESPACE_rfc2342_example_5.6:
103+
:response: &rfc2342_ex5_6 "* NAMESPACE ((\"\" \"/\") (\"#mh/\" \"/\" \"X-PARAM\" (\"FLAG1\" \"FLAG2\")))
104+
NIL NIL\r\n"
105+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
106+
name: NAMESPACE
107+
data: !ruby/struct:Net::IMAP::Namespaces
108+
personal:
109+
- !ruby/struct:Net::IMAP::Namespace
110+
prefix: ''
111+
delim: "/"
112+
extensions: {}
113+
- !ruby/struct:Net::IMAP::Namespace
114+
prefix: "#mh/"
115+
delim: "/"
116+
extensions:
117+
X-PARAM:
118+
- FLAG1
119+
- FLAG2
120+
other: []
121+
shared: []
122+
raw_data: *rfc2342_ex5_6
123+
124+
NAMESPACE_rfc2342_example_5.7:
125+
:response: &rfc2342_ex5_7 "* NAMESPACE ((\"\" \"/\")) ((\"Other Users/\" \"/\")) NIL\r\n"
126+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
127+
name: NAMESPACE
128+
data: !ruby/struct:Net::IMAP::Namespaces
129+
personal:
130+
- !ruby/struct:Net::IMAP::Namespace
131+
prefix: ''
132+
delim: "/"
133+
extensions: {}
134+
other:
135+
- !ruby/struct:Net::IMAP::Namespace
136+
prefix: Other Users/
137+
delim: "/"
138+
extensions: {}
139+
shared: []
140+
raw_data: *rfc2342_ex5_7
141+
142+
NAMESPACE_rfc9051_6.3.10_example_8:
143+
:response: &rfc9051_6_3_10_ex8 "* NAMESPACE ((\"\" \"/\")) ((\"#Users/\" \"/\")) NIL\r\n"
144+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
145+
name: NAMESPACE
146+
data: !ruby/struct:Net::IMAP::Namespaces
147+
personal:
148+
- !ruby/struct:Net::IMAP::Namespace
149+
prefix: ''
150+
delim: "/"
151+
extensions: {}
152+
other:
153+
- !ruby/struct:Net::IMAP::Namespace
154+
prefix: "#Users/"
155+
delim: "/"
156+
extensions: {}
157+
shared: []
158+
raw_data: *rfc9051_6_3_10_ex8
159+
raw_data: "* NAMESPACE ((\"\" \"/\")) ((\"#Users/\" \"/\")) NIL\r\n"
160+
161+
NAMESPACE_rfc2342_example_5.9:
162+
:response: &rfc2342_ex5_9 "* NAMESPACE ((\"\" \"/\")) ((\"~\" \"/\")) NIL\r\n"
163+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
164+
name: NAMESPACE
165+
data: !ruby/struct:Net::IMAP::Namespaces
166+
personal:
167+
- !ruby/struct:Net::IMAP::Namespace
168+
prefix: ''
169+
delim: "/"
170+
extensions: {}
171+
other:
172+
- !ruby/struct:Net::IMAP::Namespace
173+
prefix: "~"
174+
delim: "/"
175+
extensions: {}
176+
shared: []
177+
raw_data: "* NAMESPACE ((\"\" \"/\")) ((\"~\" \"/\")) NIL\r\n"

test/net/imap/test_imap_response_parser.rb

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

30+
# §7.3.2: NAMESPACE response (also RFC2342)
31+
generate_tests_from fixture_file: "namespace_responses.yml"
32+
3033
############################################################################
3134
# IMAP extensions, by RFC:
3235

@@ -362,38 +365,6 @@ def test_ignored_response
362365
assert_instance_of(Net::IMAP::IgnoredResponse, response)
363366
end
364367

365-
def test_namespace
366-
parser = Net::IMAP::ResponseParser.new
367-
# RFC2342 Example 5.1
368-
response = parser.parse(%Q{* NAMESPACE (("" "/")) NIL NIL\r\n})
369-
assert_equal("NAMESPACE", response.name)
370-
assert_equal([Net::IMAP::Namespace.new("", "/", {})], response.data.personal)
371-
assert_equal([], response.data.other)
372-
assert_equal([], response.data.shared)
373-
# RFC2342 Example 5.4
374-
response = parser.parse(%Q{* NAMESPACE (("" "/")) (("~" "/")) (("#shared/" "/")} +
375-
%Q{ ("#public/" "/") ("#ftp/" "/") ("#news." "."))\r\n})
376-
assert_equal("NAMESPACE", response.name)
377-
assert_equal([Net::IMAP::Namespace.new("", "/", {})], response.data.personal)
378-
assert_equal([Net::IMAP::Namespace.new("~", "/", {})], response.data.other)
379-
assert_equal(
380-
[
381-
Net::IMAP::Namespace.new("#shared/", "/", {}),
382-
Net::IMAP::Namespace.new("#public/", "/", {}),
383-
Net::IMAP::Namespace.new("#ftp/", "/", {}),
384-
Net::IMAP::Namespace.new("#news.", ".", {}),
385-
],
386-
response.data.shared
387-
)
388-
# RFC2342 Example 5.6
389-
response = parser.parse(%Q{* NAMESPACE (("" "/") ("#mh/" "/" "X-PARAM" ("FLAG1" "FLAG2"))) NIL NIL\r\n})
390-
assert_equal("NAMESPACE", response.name)
391-
namespace = response.data.personal.last
392-
assert_equal("#mh/", namespace.prefix)
393-
assert_equal("/", namespace.delim)
394-
assert_equal({"X-PARAM" => ["FLAG1", "FLAG2"]}, namespace.extensions)
395-
end
396-
397368
def test_uidplus_appenduid
398369
parser = Net::IMAP::ResponseParser.new
399370
# RFC4315 example

0 commit comments

Comments
 (0)