- 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.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
from prompt_toolkit.document import Document
|
|
from prompt_toolkit.validation import ValidationError
|
|
|
|
from falyx.validators import CommandValidator
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_validator_validates_command():
|
|
fake_falyx = AsyncMock()
|
|
fake_falyx.get_command.return_value = (False, object(), (), {})
|
|
validator = CommandValidator(fake_falyx, "Invalid!")
|
|
|
|
await validator.validate_async(Document("valid"))
|
|
fake_falyx.get_command.assert_awaited_once()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_validator_rejects_invalid_command():
|
|
fake_falyx = AsyncMock()
|
|
fake_falyx.get_command.return_value = (False, None, (), {})
|
|
validator = CommandValidator(fake_falyx, "Invalid!")
|
|
|
|
with pytest.raises(ValidationError):
|
|
await validator.validate_async(Document("not_a_command"))
|
|
|
|
with pytest.raises(ValidationError):
|
|
await validator.validate_async(Document(""))
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command_validator_is_preview():
|
|
fake_falyx = AsyncMock()
|
|
fake_falyx.get_command.return_value = (True, None, (), {})
|
|
validator = CommandValidator(fake_falyx, "Invalid!")
|
|
|
|
await validator.validate_async(Document("?preview_command"))
|
|
fake_falyx.get_command.assert_awaited_once_with(
|
|
"?preview_command", from_validate=True
|
|
)
|