2016-04-02 23:57:43 -03:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.git_branch_exists import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2016-04-02 23:57:43 -03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2018-01-05 21:25:08 +00:00
|
|
|
def output(src_branch_name):
|
|
|
|
return "fatal: A branch named '{}' already exists.".format(src_branch_name)
|
2016-04-02 23:57:43 -03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def new_command(branch_name):
|
|
|
|
return [cmd.format(branch_name) for cmd in [
|
|
|
|
'git branch -d {0} && git branch {0}',
|
2016-07-21 13:59:41 -03:00
|
|
|
'git branch -d {0} && git checkout -b {0}',
|
|
|
|
'git branch -D {0} && git branch {0}',
|
|
|
|
'git branch -D {0} && git checkout -b {0}', 'git checkout {0}']]
|
2016-04-02 23:57:43 -03:00
|
|
|
|
|
|
|
|
2018-01-05 21:25:08 +00:00
|
|
|
@pytest.mark.parametrize('script, src_branch_name, branch_name', [
|
|
|
|
('git branch foo', 'foo', 'foo'),
|
|
|
|
('git checkout bar', 'bar', 'bar'),
|
|
|
|
('git checkout -b "let\'s-push-this"', '"let\'s-push-this"', '"let\'s-push-this"')])
|
2017-08-31 17:58:56 +02:00
|
|
|
def test_match(output, script, branch_name):
|
|
|
|
assert match(Command(script, output))
|
2016-04-02 23:57:43 -03:00
|
|
|
|
|
|
|
|
2018-01-05 21:25:08 +00:00
|
|
|
@pytest.mark.parametrize('script', [
|
|
|
|
'git branch foo',
|
|
|
|
'git checkout bar',
|
|
|
|
'git checkout -b "let\'s-push-this"'])
|
2016-04-02 23:57:43 -03:00
|
|
|
def test_not_match(script):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert not match(Command(script, ''))
|
2016-04-02 23:57:43 -03:00
|
|
|
|
|
|
|
|
2018-01-05 21:25:08 +00:00
|
|
|
@pytest.mark.parametrize('script, src_branch_name, branch_name', [
|
|
|
|
('git branch foo', 'foo', 'foo'),
|
|
|
|
('git checkout bar', 'bar', 'bar'),
|
|
|
|
('git checkout -b "let\'s-push-this"', "let's-push-this", "let\\'s-push-this")])
|
|
|
|
def test_get_new_command(output, new_command, script, src_branch_name, branch_name):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert get_new_command(Command(script, output)) == new_command
|