Skip to content

Commit e2a4367

Browse files
committed
✅ add unit tests for markdown related utils
1 parent f3a8f1e commit e2a4367

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

tests/test_markdown_utils.py

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2021-present Pycord Development
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
DEALINGS IN THE SOFTWARE.
23+
"""
24+
25+
from discord.utils import (
26+
oauth_url,
27+
snowflake_time,
28+
find,
29+
get_or_fetch,
30+
utcnow,
31+
remove_markdown,
32+
escape_markdown,
33+
escape_mentions,
34+
raw_mentions,
35+
raw_channel_mentions,
36+
raw_role_mentions,
37+
format_dt,
38+
generate_snowflake,
39+
basic_autocomplete,
40+
)
41+
42+
43+
def test_raw_role_mentions_valid_input():
44+
text = "<@&123456789012345678> <@&987654321098765432>"
45+
result = raw_role_mentions(text)
46+
assert result == [123456789012345678, 987654321098765432]
47+
48+
49+
def test_raw_role_mentions_no_mentions():
50+
text = "This text has no role mentions."
51+
result = raw_role_mentions(text)
52+
assert result == []
53+
54+
55+
def test_raw_role_mentions_mixed_mentions():
56+
text = "<@123456789012345678> <@&987654321098765432> <#123456789012345678>"
57+
result = raw_role_mentions(text)
58+
assert result == [987654321098765432]
59+
60+
61+
def test_raw_role_mentions_invalid_format():
62+
text = "<@&invalid123> <@&123abc456>"
63+
result = raw_role_mentions(text)
64+
assert result == []
65+
66+
67+
def test_raw_role_mentions_empty_string():
68+
text = ""
69+
result = raw_role_mentions(text)
70+
assert result == []
71+
72+
73+
def test_raw_channel_mentions_valid_input():
74+
text = "<#123456789012345678> <#987654321098765432>"
75+
result = raw_channel_mentions(text)
76+
assert result == [123456789012345678, 987654321098765432]
77+
78+
79+
def test_raw_channel_mentions_no_mentions():
80+
text = "This text has no channel mentions."
81+
result = raw_channel_mentions(text)
82+
assert result == []
83+
84+
85+
def test_raw_channel_mentions_mixed_mentions():
86+
text = "<@123456789012345678> <#987654321098765432> <@&123456789012345678>"
87+
result = raw_channel_mentions(text)
88+
assert result == [987654321098765432]
89+
90+
91+
def test_raw_channel_mentions_invalid_format():
92+
text = "<#invalid123> <#123abc456>"
93+
result = raw_channel_mentions(text)
94+
assert result == []
95+
96+
97+
def test_raw_channel_mentions_empty_string():
98+
text = ""
99+
result = raw_channel_mentions(text)
100+
assert result == []
101+
102+
103+
def test_raw_mentions_valid_input():
104+
text = "<@123456789012345678> <@!987654321098765432>"
105+
result = raw_mentions(text)
106+
assert result == [123456789012345678, 987654321098765432]
107+
108+
109+
def test_raw_mentions_no_mentions():
110+
text = "This text has no user mentions."
111+
result = raw_mentions(text)
112+
assert result == []
113+
114+
115+
def test_raw_mentions_mixed_mentions():
116+
text = "<@123456789012345678> <#987654321098765432> <@&123456789012345678>"
117+
result = raw_mentions(text)
118+
assert result == [123456789012345678]
119+
120+
121+
def test_raw_mentions_invalid_format():
122+
text = "<@invalid123> <@!123abc456>"
123+
result = raw_mentions(text)
124+
assert result == []
125+
126+
127+
def test_raw_mentions_empty_string():
128+
text = ""
129+
result = raw_mentions(text)
130+
assert result == []
131+
132+
133+
def test_escape_mentions_removes_everyone_and_here():
134+
text = "@everyone @here"
135+
result = escape_mentions(text)
136+
assert result == "@\u200beveryone @\u200bhere"
137+
138+
139+
def test_escape_mentions_ignores_channel_mentions():
140+
text = "<#123456789012345678>"
141+
result = escape_mentions(text)
142+
assert result == "<#123456789012345678>"
143+
144+
145+
def test_escape_mentions_empty_string():
146+
text = ""
147+
result = escape_mentions(text)
148+
assert result == ""
149+
150+
151+
def test_escape_mentions_removes_user_and_role_mentions():
152+
text = "<@123456789012345678> <@!987654321098765432> <@&123456789012345678>"
153+
result = escape_mentions(text)
154+
assert result == "<@\u200b123456789012345678> <@\u200b!987654321098765432> <@\u200b&123456789012345678>"
155+
156+
157+
def test_escape_mentions_handles_mixed_mentions():
158+
text = "@everyone <@123456789012345678> @here <#987654321098765432>"
159+
result = escape_mentions(text)
160+
assert result == "@\u200beveryone <@\u200b123456789012345678> @\u200bhere <#987654321098765432>"

0 commit comments

Comments
 (0)