mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 05:31:18 +00:00
Stop parsing language-variable cat output to make cat_dir more reliable. (#827)
* Stop parsing language-variable cat output to make cat_dir more reliable. * Add missing semicolon in readme
This commit is contained in:
parent
fe0785bc42
commit
1dfd6373ee
@ -177,7 +177,7 @@ following rules are enabled by default:
|
|||||||
* `aws_cli` – fixes misspelled commands like `aws dynamdb scan`;
|
* `aws_cli` – fixes misspelled commands like `aws dynamdb scan`;
|
||||||
* `cargo` – runs `cargo build` instead of `cargo`;
|
* `cargo` – runs `cargo build` instead of `cargo`;
|
||||||
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
||||||
* `cat_dir` – replaces `cat` with `ls` when you try to `cat` a directory
|
* `cat_dir` – replaces `cat` with `ls` when you try to `cat` a directory;
|
||||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
* `cd_correction` – spellchecks and correct failed cd commands;
|
||||||
* `cd_mkdir` – creates directories before cd'ing into them;
|
* `cd_mkdir` – creates directories before cd'ing into them;
|
||||||
* `cd_parent` – changes `cd..` to `cd ..`;
|
* `cd_parent` – changes `cd..` to `cd ..`;
|
||||||
|
@ -3,20 +3,29 @@ from thefuck.rules.cat_dir import match, get_new_command
|
|||||||
from thefuck.types import Command
|
from thefuck.types import Command
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def isdir(mocker):
|
||||||
|
return mocker.patch('thefuck.rules.cat_dir'
|
||||||
|
'.os.path.isdir')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
Command('cat foo', 'cat: foo: Is a directory\n'),
|
Command('cat foo', 'cat: foo: Is a directory\n'),
|
||||||
Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'),
|
Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'),
|
||||||
Command('cat cat/', 'cat: cat/: Is a directory\n'),
|
Command('cat cat/', 'cat: cat/: Is a directory\n'),
|
||||||
])
|
])
|
||||||
def test_match(command):
|
def test_match(command, isdir):
|
||||||
|
isdir.return_value = True
|
||||||
assert match(command)
|
assert match(command)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
Command('cat foo', 'foo bar baz'),
|
Command('cat foo', 'foo bar baz'),
|
||||||
Command('cat foo bar', 'foo bar baz'),
|
Command('cat foo bar', 'foo bar baz'),
|
||||||
|
Command('notcat foo bar', 'some output'),
|
||||||
])
|
])
|
||||||
def test_not_match(command):
|
def test_not_match(command, isdir):
|
||||||
|
isdir.return_value = False
|
||||||
assert not match(command)
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
@ -26,4 +35,5 @@ def test_not_match(command):
|
|||||||
(Command('cat cat', 'cat: cat: Is a directory\n'), 'ls cat'),
|
(Command('cat cat', 'cat: cat: Is a directory\n'), 'ls cat'),
|
||||||
])
|
])
|
||||||
def test_get_new_command(command, new_command):
|
def test_get_new_command(command, new_command):
|
||||||
|
isdir.return_value = True
|
||||||
assert get_new_command(command) == new_command
|
assert get_new_command(command) == new_command
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from thefuck.utils import for_app
|
||||||
|
|
||||||
|
|
||||||
|
@for_app('cat')
|
||||||
def match(command):
|
def match(command):
|
||||||
return (
|
return (
|
||||||
command.script.startswith('cat') and
|
|
||||||
command.output.startswith('cat: ') and
|
command.output.startswith('cat: ') and
|
||||||
command.output.rstrip().endswith(': Is a directory')
|
os.path.isdir(command.script_parts[1])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user