feat: add path completion, LCP-based suggestions, and validator tests
- Refactored `FalyxCompleter` to support longest common prefix (LCP) completions by default. - Added `_ensure_quote` helper to auto-quote completions containing spaces/tabs. - Integrated `_yield_lcp_completions` for consistent completion insertion logic. - Added `_suggest_paths()` helper to dynamically suggest filesystem paths for arguments of type `Path`. - Integrated path completion into `suggest_next()` for both positional and flagged arguments. - Updated `argument_examples.py` to include a `--path` argument (`Path | None`), demonstrating file path completion. - Enabled `CompleteStyle.COLUMN` for tab-completion menu formatting in interactive sessions. - Improved bottom bar docstring formatting with fenced code block examples. - Added safeguard to `word_validator` to reject `"N"` since it’s reserved for `yes_no_validator`. - Improved help panel rendering for commands (using `Padding` + `Panel`). - Added full test coverage for: - `FalyxCompleter` and LCP behavior (`tests/test_completer/`) - All validators (`tests/test_validators/`) - Bumped version to 0.1.80.
This commit is contained in:
38
tests/test_completer/test_lcp_completions.py
Normal file
38
tests/test_completer/test_lcp_completions.py
Normal file
@ -0,0 +1,38 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from prompt_toolkit.document import Document
|
||||
|
||||
from falyx.completer import FalyxCompleter
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_falyx():
|
||||
fake_arg_parser = SimpleNamespace(
|
||||
suggest_next=lambda tokens, end: ["AETHERWARP", "AETHERZOOM"]
|
||||
)
|
||||
fake_command = SimpleNamespace(key="R", aliases=["RUN"], arg_parser=fake_arg_parser)
|
||||
return SimpleNamespace(
|
||||
exit_command=SimpleNamespace(key="X", aliases=["EXIT"]),
|
||||
help_command=SimpleNamespace(key="H", aliases=["HELP"]),
|
||||
history_command=SimpleNamespace(key="Y", aliases=["HISTORY"]),
|
||||
commands={"R": fake_command},
|
||||
_name_map={"R": fake_command, "RUN": fake_command, "X": fake_command},
|
||||
)
|
||||
|
||||
|
||||
def test_lcp_completions(fake_falyx):
|
||||
completer = FalyxCompleter(fake_falyx)
|
||||
doc = Document("R A")
|
||||
results = list(completer.get_completions(doc, None))
|
||||
assert any(c.text == "AETHER" for c in results)
|
||||
assert any(c.text == "AETHERWARP" for c in results)
|
||||
assert any(c.text == "AETHERZOOM" for c in results)
|
||||
|
||||
|
||||
def test_lcp_completions_space(fake_falyx):
|
||||
completer = FalyxCompleter(fake_falyx)
|
||||
suggestions = ["London", "New York", "San Francisco"]
|
||||
stub = "N"
|
||||
completions = list(completer._yield_lcp_completions(suggestions, stub))
|
||||
assert any(c.text == '"New York"' for c in completions)
|
Reference in New Issue
Block a user