mirror of
https://github.com/progval/irctest.git
synced 2025-04-04 22:39:50 +00:00
patma: Add support for operators in keys
Will be used to match either '@bot' or '@draft/bot'.
This commit is contained in:
@ -155,13 +155,15 @@ def match_dict(
|
||||
for (expected_key, expected_value) in expected.items():
|
||||
if isinstance(expected_key, RemainingKeys):
|
||||
remaining_keys_wildcard = (expected_key.key, expected_value)
|
||||
elif isinstance(expected_key, Operator):
|
||||
raise NotImplementedError(f"Unsupported operator: {expected_key}")
|
||||
else:
|
||||
if expected_key not in got:
|
||||
return False
|
||||
got_value = got.pop(expected_key)
|
||||
if not match_string(got_value, expected_value):
|
||||
for key in got:
|
||||
if match_string(key, expected_key) and match_string(
|
||||
got[key], expected_value
|
||||
):
|
||||
got.pop(key)
|
||||
break
|
||||
else:
|
||||
# Found no (key, value) pair matching the request
|
||||
return False
|
||||
|
||||
if remaining_keys_wildcard:
|
||||
|
@ -179,6 +179,39 @@ MESSAGE_SPECS: List[Tuple[Dict, List[str], List[str], List[str]]] = [
|
||||
"expected tags to match {'tag1': 'bar', RemainingKeys(ANYSTR): ANYOPTSTR}, got {}",
|
||||
]
|
||||
),
|
||||
(
|
||||
# the specification:
|
||||
dict(
|
||||
tags={StrRe("tag[12]"): "bar", **ANYDICT},
|
||||
command="PRIVMSG",
|
||||
params=["#chan", "hello"],
|
||||
),
|
||||
# matches:
|
||||
[
|
||||
"@tag1=bar PRIVMSG #chan :hello",
|
||||
"@tag1=bar;tag2= PRIVMSG #chan :hello",
|
||||
"@tag1=bar :foo!baz@qux PRIVMSG #chan :hello",
|
||||
"@tag2=bar PRIVMSG #chan :hello",
|
||||
"@tag1=bar;tag2= PRIVMSG #chan :hello",
|
||||
"@tag1=;tag2=bar PRIVMSG #chan :hello",
|
||||
],
|
||||
# and does not match:
|
||||
[
|
||||
"PRIVMG #chan :hello",
|
||||
"@tag1=value1 PRIVMSG #chan :hello",
|
||||
"PRIVMSG #chan hello2",
|
||||
"PRIVMSG #chan2 hello",
|
||||
":foo!baz@qux PRIVMSG #chan hello",
|
||||
],
|
||||
# and they each error with:
|
||||
[
|
||||
"expected command to be PRIVMSG, got PRIVMG",
|
||||
"expected tags to match {StrRe(r'tag[12]'): 'bar', RemainingKeys(ANYSTR): ANYOPTSTR}, got {'tag1': 'value1'}",
|
||||
"expected params to match ['#chan', 'hello'], got ['#chan', 'hello2']",
|
||||
"expected params to match ['#chan', 'hello'], got ['#chan2', 'hello']",
|
||||
"expected tags to match {StrRe(r'tag[12]'): 'bar', RemainingKeys(ANYSTR): ANYOPTSTR}, got {}",
|
||||
]
|
||||
),
|
||||
(
|
||||
# the specification:
|
||||
dict(
|
||||
|
Reference in New Issue
Block a user