2021-04-13 15:58:20 -04:00
|
|
|
import pytest
|
2021-05-10 11:42:13 -04:00
|
|
|
from thefuck.rules.chdir import match, get_new_command
|
2021-04-13 15:58:20 -04:00
|
|
|
from thefuck.types import Command
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command', [
|
|
|
|
Command('chdir foo', 'cannot find the path'),
|
|
|
|
Command('chdir foo/bar', 'can\'t cd to'),
|
2021-05-10 11:42:13 -04:00
|
|
|
Command('chdir foo/bar', 'cannot find path'),
|
2021-04-13 15:58:20 -04:00
|
|
|
Command('chdir /foo/bar/', 'can\'t cd to')])
|
|
|
|
def test_match(command):
|
|
|
|
assert match(command)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command', [
|
|
|
|
Command('chdir foo', ''), Command('', '')])
|
|
|
|
def test_not_match(command):
|
|
|
|
assert not match(command)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command, new_command', [
|
2021-05-10 11:42:13 -04:00
|
|
|
(Command('chdirfoo', ''), 'mkdir -p foo; chdir foo'),
|
|
|
|
(Command('chdirfoo/bar/baz', ''), 'mkdir -p foo/bar/baz; chdir foo/bar/baz')])
|
2021-04-13 15:58:20 -04:00
|
|
|
def test_get_new_command(command, new_command):
|
|
|
|
assert get_new_command(command) == new_command
|
2021-05-10 11:42:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('command', [
|
|
|
|
Command('chdir <', ''), Command('chdir \0', '')])
|
|
|
|
def test_bad_dir_name(command):
|
|
|
|
assert not match(command)
|