mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
More tests for commands filter
This commit is contained in:
parent
cb91086106
commit
e43bc5b2fe
2 changed files with 11 additions and 1 deletions
|
|
@ -41,6 +41,9 @@ class Command(BaseFilter):
|
||||||
:param bot:
|
:param bot:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if not text.strip():
|
||||||
|
return False
|
||||||
|
|
||||||
# First step: separate command with arguments
|
# First step: separate command with arguments
|
||||||
# "/command@mention arg1 arg2" -> "/command@mention", ["arg1 arg2"]
|
# "/command@mention arg1 arg2" -> "/command@mention", ["arg1 arg2"]
|
||||||
full_command, *args = text.split(maxsplit=1)
|
full_command, *args = text.split(maxsplit=1)
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,17 @@ class TestCommandFilter:
|
||||||
)
|
)
|
||||||
command = Command(commands=["test", re.compile(r"test(\d+)")], commands_prefix="/")
|
command = Command(commands=["test", re.compile(r"test(\d+)")], commands_prefix="/")
|
||||||
|
|
||||||
|
assert await command.parse_command("/test@tbot", bot)
|
||||||
assert not await command.parse_command("!test", bot)
|
assert not await command.parse_command("!test", bot)
|
||||||
assert not await command.parse_command("/test@mention", bot)
|
assert not await command.parse_command("/test@mention", bot)
|
||||||
assert await command.parse_command("/test@tbot", bot)
|
|
||||||
assert not await command.parse_command("/tests", bot)
|
assert not await command.parse_command("/tests", bot)
|
||||||
|
assert not await command.parse_command("/", bot)
|
||||||
|
assert not await command.parse_command("/ test", bot)
|
||||||
|
assert not await command.parse_command("", bot)
|
||||||
|
assert not await command.parse_command(" ", bot)
|
||||||
|
assert not await command.parse_command("test", bot)
|
||||||
|
assert not await command.parse_command(" test", bot)
|
||||||
|
assert not await command.parse_command("a", bot)
|
||||||
|
|
||||||
result = await command.parse_command("/test@tbot some args", bot)
|
result = await command.parse_command("/test@tbot some args", bot)
|
||||||
assert isinstance(result, dict)
|
assert isinstance(result, dict)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue