|
| 1 | +import pytest |
| 2 | + |
| 3 | +from thefuck.rules.git_branch_0flag import get_new_command, match |
| 4 | +from thefuck.types import Command |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture |
| 8 | +def output_branch_exists(): |
| 9 | + return "fatal: A branch named 'bar' already exists." |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.parametrize( |
| 13 | + "script", |
| 14 | + [ |
| 15 | + "git branch 0a", |
| 16 | + "git branch 0d", |
| 17 | + "git branch 0f", |
| 18 | + "git branch 0r", |
| 19 | + "git branch 0v", |
| 20 | + "git branch 0d foo", |
| 21 | + "git branch 0D foo", |
| 22 | + ], |
| 23 | +) |
| 24 | +def test_match(script, output_branch_exists): |
| 25 | + assert match(Command(script, output_branch_exists)) |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.parametrize( |
| 29 | + "script", |
| 30 | + [ |
| 31 | + "git branch -a", |
| 32 | + "git branch -r", |
| 33 | + "git branch -v", |
| 34 | + "git branch -d foo", |
| 35 | + "git branch -D foo", |
| 36 | + ], |
| 37 | +) |
| 38 | +def test_not_match(script, output_branch_exists): |
| 39 | + assert not match(Command(script, "")) |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.parametrize( |
| 43 | + "script, new_command", |
| 44 | + [ |
| 45 | + ("git branch 0a", "git branch -D 0a && git branch -a"), |
| 46 | + ("git branch 0v", "git branch -D 0v && git branch -v"), |
| 47 | + ("git branch 0d foo", "git branch -D 0d && git branch -d foo"), |
| 48 | + ("git branch 0D foo", "git branch -D 0D && git branch -D foo"), |
| 49 | + ("git branch 0l 'maint-*'", "git branch -D 0l && git branch -l 'maint-*'"), |
| 50 | + ("git branch 0u upstream", "git branch -D 0u && git branch -u upstream"), |
| 51 | + ], |
| 52 | +) |
| 53 | +def test_get_new_command_branch_exists(script, output_branch_exists, new_command): |
| 54 | + assert get_new_command(Command(script, output_branch_exists)) == new_command |
| 55 | + |
| 56 | + |
| 57 | +@pytest.fixture |
| 58 | +def output_not_valid_object(): |
| 59 | + return "fatal: Not a valid object name: 'bar'." |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.parametrize( |
| 63 | + "script, new_command", |
| 64 | + [ |
| 65 | + ("git branch 0l 'maint-*'", "git branch -l 'maint-*'"), |
| 66 | + ("git branch 0u upstream", "git branch -u upstream"), |
| 67 | + ], |
| 68 | +) |
| 69 | +def test_get_new_command_not_valid_object(script, output_not_valid_object, new_command): |
| 70 | + assert get_new_command(Command(script, output_not_valid_object)) == new_command |
0 commit comments