mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 14:48:49 +00:00
Changed to string methods in response to feedback.
Added a test to make sure lines like 'cat cat' don't become 'ls ls'. Added trailing '\n's to test cases.
This commit is contained in:
parent
d52765ff84
commit
c3be882620
@ -4,8 +4,9 @@ from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('cat foo', 'cat: foo: Is a directory'),
|
||||
Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory'),
|
||||
Command('cat foo', 'cat: foo: Is a directory\n'),
|
||||
Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'),
|
||||
Command('cat cat/', 'cat: cat/: Is a directory\n'),
|
||||
])
|
||||
def test_match(command):
|
||||
assert match(command)
|
||||
@ -14,15 +15,15 @@ def test_match(command):
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('cat foo', 'foo bar baz'),
|
||||
Command('cat foo bar', 'foo bar baz'),
|
||||
Command('', ''),
|
||||
])
|
||||
def test_not_match(command):
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('cat foo', 'cat: foo: Is a directory'), 'ls foo'),
|
||||
(Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory'), 'ls /foo/bar/'),
|
||||
(Command('cat foo', 'cat: foo: Is a directory\n'), 'ls foo'),
|
||||
(Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'), 'ls /foo/bar/'),
|
||||
(Command('cat cat', 'cat: cat: Is a directory\n'), 'ls cat'),
|
||||
])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command) == new_command
|
||||
|
@ -1,12 +1,10 @@
|
||||
import re
|
||||
|
||||
|
||||
def match(command):
|
||||
return (
|
||||
command.script.startswith('cat') and
|
||||
re.match(r'cat: .+: Is a directory', command.output)
|
||||
command.output.startswith('cat: ') and
|
||||
command.output.rstrip().endswith(': Is a directory')
|
||||
)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return re.sub(r'^cat', 'ls', command.script)
|
||||
return command.script.replace('cat', 'ls', 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user