import pytest
from theheck.rules.git_rm_local_modifications import match, get_new_command
from theheck.types import Command


@pytest.fixture
def output(target):
    return ('error: the following file has local modifications:\n    {}\n(use '
            '--cached to keep the file, or -f to force removal)').format(target)


@pytest.mark.parametrize('script, target', [
    ('git rm foo', 'foo'),
    ('git rm foo bar', 'bar')])
def test_match(output, script, target):
    assert match(Command(script, output))


@pytest.mark.parametrize('script', ['git rm foo', 'git rm foo bar', 'git rm'])
def test_not_match(script):
    assert not match(Command(script, ''))


@pytest.mark.parametrize('script, target, new_command', [
    ('git rm foo', 'foo', ['git rm --cached foo', 'git rm -f foo']),
    ('git rm foo bar', 'bar', ['git rm --cached foo bar', 'git rm -f foo bar'])])
def test_get_new_command(output, script, target, new_command):
    assert get_new_command(Command(script, output)) == new_command

[((12, 1, 14, 31), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(12, 25, 12, 41): '"""script, target"""', (12, 43, 14, 30): "[('git rm foo', 'foo'), ('git rm foo bar', 'bar')]"}, {}), "('script, target', [('git rm foo', 'foo'), (\n    'git rm foo bar', 'bar')])", False, 'import pytest\n'), ((19, 1, 19, 78), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(19, 25, 19, 33): '"""script"""', (19, 35, 19, 77): "['git rm foo', 'git rm foo bar', 'git rm']"}, {}), "('script', ['git rm foo', 'git rm foo bar', 'git rm'])", False, 'import pytest\n'), ((24, 1, 26, 81), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(24, 25, 24, 54): '"""script, target, new_command"""', (24, 56, 26, 80): "[('git rm foo', 'foo', ['git rm --cached foo', 'git rm -f foo']), (\n    'git rm foo bar', 'bar', ['git rm --cached foo bar', 'git rm -f foo bar'])]"}, {}), "('script, target, new_command', [('git rm foo',\n    'foo', ['git rm --cached foo', 'git rm -f foo']), ('git rm foo bar',\n    'bar', ['git rm --cached foo bar', 'git rm -f foo bar'])])", False, 'import pytest\n'), ((16, 17, 16, 40), 'theheck.types.Command', 'Command', ({(16, 25, 16, 31): 'script', (16, 33, 16, 39): 'output'}, {}), '(script, output)', False, 'from theheck.types import Command\n'), ((21, 21, 21, 40), 'theheck.types.Command', 'Command', ({(21, 29, 21, 35): 'script', (21, 37, 21, 39): '""""""'}, {}), "(script, '')", False, 'from theheck.types import Command\n'), ((28, 27, 28, 50), 'theheck.types.Command', 'Command', ({(28, 35, 28, 41): 'script', (28, 43, 28, 49): 'output'}, {}), '(script, output)', False, 'from theheck.types import Command\n')]