mirror of
https://github.com/progval/irctest.git
synced 2025-04-05 06:49:47 +00:00
Add test for ISUPPORT PREFIX. (#128)
This commit is contained in:
@ -4,6 +4,64 @@ from irctest import cases, runner
|
||||
|
||||
|
||||
class IsupportTestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_specifications("Modern")
|
||||
@cases.mark_isupport("PREFIX")
|
||||
def testPrefix(self):
|
||||
"""https://modern.ircdocs.horse/#prefix-parameter"""
|
||||
self.connectClient("foo")
|
||||
|
||||
if "PREFIX" not in self.server_support:
|
||||
raise runner.NotImplementedByController("PREFIX")
|
||||
|
||||
if self.server_support["PREFIX"] == "":
|
||||
# "The value is OPTIONAL and when it is not specified indicates that no
|
||||
# prefixes are supported."
|
||||
return
|
||||
|
||||
m = re.match(
|
||||
r"\((?P<modes>[a-zA-Z]+)\)(?P<prefixes>\S+)", self.server_support["PREFIX"]
|
||||
)
|
||||
self.assertTrue(
|
||||
m,
|
||||
f"PREFIX={self.server_support['PREFIX']} does not have the expected "
|
||||
f"format.",
|
||||
)
|
||||
|
||||
modes = m.group("modes")
|
||||
prefixes = m.group("prefixes")
|
||||
|
||||
# "There is a one-to-one mapping between prefixes and channel modes."
|
||||
self.assertEqual(
|
||||
len(modes), len(prefixes), "Mismatched length of prefix and channel modes."
|
||||
)
|
||||
|
||||
# "The prefixes in this parameter are in descending order, from the prefix
|
||||
# that gives the most privileges to the prefix that gives the least."
|
||||
self.assertLess(modes.index("o"), modes.index("v"), "'o' is not before 'v'")
|
||||
if "h" in modes:
|
||||
self.assertLess(modes.index("o"), modes.index("h"), "'o' is not before 'h'")
|
||||
self.assertLess(modes.index("h"), modes.index("v"), "'h' is not before 'v'")
|
||||
if "q" in modes:
|
||||
self.assertLess(modes.index("q"), modes.index("o"), "'q' is not before 'o'")
|
||||
|
||||
# Not technically in the spec, but it would be very confusing not to follow
|
||||
# these conventions.
|
||||
mode_to_prefix = dict(zip(modes, prefixes))
|
||||
self.assertEqual(mode_to_prefix["o"], "@", "Prefix char for mode +o is not @")
|
||||
self.assertEqual(mode_to_prefix["v"], "+", "Prefix char for mode +v is not +")
|
||||
if "h" in modes:
|
||||
self.assertEqual(
|
||||
mode_to_prefix["h"], "%", "Prefix char for mode +h is not %"
|
||||
)
|
||||
if "q" in modes:
|
||||
self.assertEqual(
|
||||
mode_to_prefix["q"], "~", "Prefix char for mode +q is not ~"
|
||||
)
|
||||
if "a" in modes:
|
||||
self.assertEqual(
|
||||
mode_to_prefix["a"], "&", "Prefix char for mode +a is not &"
|
||||
)
|
||||
|
||||
@cases.mark_specifications("Modern", "ircdocs")
|
||||
@cases.mark_isupport("TARGMAX")
|
||||
def testTargmax(self):
|
||||
|
@ -50,6 +50,7 @@ class Capabilities(enum.Enum):
|
||||
@enum.unique
|
||||
class IsupportTokens(enum.Enum):
|
||||
BOT = "BOT"
|
||||
PREFIX = "PREFIX"
|
||||
MONITOR = "MONITOR"
|
||||
STATUSMSG = "STATUSMSG"
|
||||
TARGMAX = "TARGMAX"
|
||||
|
@ -33,6 +33,7 @@ markers =
|
||||
# isupport tokens
|
||||
BOT
|
||||
MONITOR
|
||||
PREFIX
|
||||
STATUSMSG
|
||||
TARGMAX
|
||||
WHOX
|
||||
|
Reference in New Issue
Block a user