Implement prefix matching in dispatch
This commit is contained in:
parent
7d3b02f6ff
commit
7c313ae307
1 changed files with 12 additions and 20 deletions
|
|
@ -80,21 +80,17 @@ async def test_prefix_match_resolves_unique_prefix(player):
|
|||
async def test_ambiguous_prefix_two_matches(player):
|
||||
"""Test that ambiguous prefix with 2 matches shows 'A or B?' message."""
|
||||
commands.register(
|
||||
CommandDefinition(name="sweep", handler=dummy_handler, mode="normal")
|
||||
CommandDefinition(name="swoop", handler=dummy_handler, mode="normal")
|
||||
)
|
||||
commands.register(
|
||||
CommandDefinition(
|
||||
name="southwest", handler=dummy_handler, mode="normal"
|
||||
)
|
||||
CommandDefinition(name="swallow", handler=dummy_handler, mode="normal")
|
||||
)
|
||||
|
||||
await commands.dispatch(player, "sw")
|
||||
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
|
||||
|
||||
# Check for either order
|
||||
assert (
|
||||
"sweep or southwest?" in output or "southwest or sweep?" in output
|
||||
)
|
||||
assert "swallow or swoop?" in output or "swoop or swallow?" in output
|
||||
assert "Handler called" not in output
|
||||
|
||||
|
||||
|
|
@ -108,9 +104,7 @@ async def test_ambiguous_prefix_three_plus_matches(player):
|
|||
CommandDefinition(name="set", handler=dummy_handler, mode="normal")
|
||||
)
|
||||
commands.register(
|
||||
CommandDefinition(
|
||||
name="settings", handler=dummy_handler, mode="normal"
|
||||
)
|
||||
CommandDefinition(name="settings", handler=dummy_handler, mode="normal")
|
||||
)
|
||||
|
||||
await commands.dispatch(player, "se")
|
||||
|
|
@ -183,8 +177,8 @@ async def test_prefix_match_deduplicates_aliases(player):
|
|||
"""Test that aliases to the same command don't create multiple matches."""
|
||||
commands.register(
|
||||
CommandDefinition(
|
||||
name="look",
|
||||
aliases=["l", "lo"],
|
||||
name="long",
|
||||
aliases=["l", "lon"],
|
||||
handler=dummy_handler,
|
||||
mode="normal",
|
||||
)
|
||||
|
|
@ -196,16 +190,14 @@ async def test_prefix_match_deduplicates_aliases(player):
|
|||
await commands.dispatch(player, "lo")
|
||||
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
|
||||
|
||||
# Should show just "lock or look?" not multiple entries for look's aliases
|
||||
# Should show just "lock or long?" not multiple entries for long's aliases
|
||||
assert "lock" in output
|
||||
assert "look" in output
|
||||
# Should not list look multiple times
|
||||
assert "long" in output
|
||||
# Should not list long multiple times
|
||||
output_lower = output.lower()
|
||||
# Count occurrences of the word "look" (not as substring)
|
||||
look_count = len(
|
||||
[word for word in output_lower.split() if word.startswith("look")]
|
||||
)
|
||||
assert look_count == 1
|
||||
# Count occurrences of the word "long" (not as substring like "lock")
|
||||
# Looking for "long" as a standalone word in disambiguation
|
||||
assert output_lower.count("long") == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Reference in a new issue