55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from src.command_palette import Command, ScoredCommand, fuzzy_match
|
|
|
|
|
|
def _cmd(id: str, title: str) -> Command:
|
|
return Command(id=id, title=title, category="test")
|
|
|
|
|
|
def test_fuzzy_match_prefix_ranks_first():
|
|
candidates = [
|
|
_cmd("find", "Find in Selection"),
|
|
_cmd("fold", "Fold All"),
|
|
_cmd("config", "Configure Settings"),
|
|
]
|
|
results = fuzzy_match("fin", candidates, top_n=10)
|
|
assert len(results) > 0
|
|
assert results[0].command.id == "find"
|
|
assert results[0].score > 0.5
|
|
|
|
|
|
def test_fuzzy_match_subsequence_match():
|
|
candidates = [_cmd("x", "Find")]
|
|
results = fuzzy_match("fd", candidates, top_n=10)
|
|
assert len(results) == 1
|
|
assert results[0].command.id == "x"
|
|
|
|
|
|
def test_fuzzy_match_no_match_returns_empty():
|
|
candidates = [_cmd("x", "foo bar")]
|
|
results = fuzzy_match("xyz", candidates, top_n=10)
|
|
assert results == []
|
|
|
|
|
|
def test_fuzzy_match_top_n_limits_results():
|
|
candidates = [_cmd(f"cmd_{i}", f"Command {i}") for i in range(50)]
|
|
results = fuzzy_match("cmd", candidates, top_n=10)
|
|
assert len(results) == 10
|
|
|
|
|
|
def test_fuzzy_match_score_higher_for_exact_prefix():
|
|
candidates = [
|
|
_cmd("a", "find"),
|
|
_cmd("b", "Configure Find Settings"),
|
|
]
|
|
results = fuzzy_match("fin", candidates, top_n=10)
|
|
assert results[0].command.id == "a"
|
|
|
|
|
|
def test_commands_registry_has_core_commands():
|
|
from src.commands import registry
|
|
all_ids = {c.id for c in registry.all()}
|
|
assert "reset_session" in all_ids
|
|
assert "clear_discussion" in all_ids
|
|
assert "trigger_hot_reload" in all_ids
|
|
assert "show_documentation" in all_ids
|