From 7c313ae307a02e1738d1240a4a52b843ed3b9ceb Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sun, 8 Feb 2026 13:33:22 -0500 Subject: [PATCH] Implement prefix matching in dispatch --- tests/test_prefix_matching.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/tests/test_prefix_matching.py b/tests/test_prefix_matching.py index bcc41b4..0b77dbd 100644 --- a/tests/test_prefix_matching.py +++ b/tests/test_prefix_matching.py @@ -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