Add script detection, env shebang parser, and opt-in content guessing
This commit is contained in:
@@ -74,6 +74,7 @@ class TestFileInput:
|
||||
path=str(file),
|
||||
content="x = 1\n",
|
||||
explicit_type=None,
|
||||
guess_content=False,
|
||||
)
|
||||
|
||||
def test_render_called_with_correct_options(self, tmp_file) -> None:
|
||||
@@ -180,6 +181,7 @@ class TestStdinInput:
|
||||
path=None,
|
||||
content="hello\n",
|
||||
explicit_type=None,
|
||||
guess_content=False,
|
||||
)
|
||||
|
||||
def test_stdin_shows_tty_prompt(self) -> None:
|
||||
@@ -216,6 +218,7 @@ class TestTypeOverride:
|
||||
|
||||
_, kwargs = mock_detect_type.call_args
|
||||
assert kwargs["explicit_type"] == "json"
|
||||
assert kwargs["guess_content"] is False
|
||||
|
||||
def test_explicit_type_short_flag(self, tmp_file) -> None:
|
||||
file = tmp_file("def foo(): pass\n", suffix=".txt")
|
||||
@@ -236,6 +239,28 @@ class TestThemeOption:
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
class TestGuessContentOption:
|
||||
"""Tests for the guess-content flag."""
|
||||
|
||||
def test_guess_content_is_forwarded(self) -> None:
|
||||
with patch("rp.cli.detect_type") as mock_detect_type:
|
||||
mock_detect_type.return_value = "diff"
|
||||
with patch("rp.cli.render"):
|
||||
runner.invoke(app, ["--guess-content", "--no-pager"], input="hello\n")
|
||||
|
||||
_, kwargs = mock_detect_type.call_args
|
||||
assert kwargs["guess_content"] is True
|
||||
|
||||
def test_guess_content_disabled_by_default(self) -> None:
|
||||
with patch("rp.cli.detect_type") as mock_detect_type:
|
||||
mock_detect_type.return_value = "text"
|
||||
with patch("rp.cli.render"):
|
||||
runner.invoke(app, ["--no-pager"], input="hello\n")
|
||||
|
||||
_, kwargs = mock_detect_type.call_args
|
||||
assert kwargs["guess_content"] is False
|
||||
|
||||
|
||||
class TestLineNumbersOption:
|
||||
"""Tests for the line number flags."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user