2015-04-23 17:42:03 +09:00
|
|
|
import pytest
|
2022-07-02 15:06:00 +02:00
|
|
|
from thefuck.rules.brew_install import match, get_new_command, _get_suggestions
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-04-23 17:42:03 +09:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-07-02 15:06:00 +02:00
|
|
|
def brew_no_available_formula_one():
|
|
|
|
return '''Warning: No available formula with the name "giss". Did you mean gist?'''
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def brew_no_available_formula_two():
|
|
|
|
return '''Warning: No available formula with the name "elasticserar". Did you mean elasticsearch or elasticsearch@6?'''
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def brew_no_available_formula_three():
|
|
|
|
return '''Warning: No available formula with the name "gitt". Did you mean git, gitg or gist?'''
|
2015-04-23 17:42:03 +09:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def brew_install_no_argument():
|
2022-07-02 15:06:00 +02:00
|
|
|
return '''Install a formula or cask. Additional options specific to a formula may be'''
|
2015-04-23 17:42:03 +09:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def brew_already_installed():
|
|
|
|
return '''Warning: git-2.3.5 already installed'''
|
|
|
|
|
|
|
|
|
2022-07-02 15:06:00 +02:00
|
|
|
def test_suggestions():
|
|
|
|
assert _get_suggestions("one") == ['one']
|
|
|
|
assert _get_suggestions("one or two") == ['one', 'two']
|
|
|
|
assert _get_suggestions("one, two or three") == ['one', 'two', 'three']
|
2015-04-23 17:42:03 +09:00
|
|
|
|
|
|
|
|
2022-07-02 15:06:00 +02:00
|
|
|
def test_match(brew_no_available_formula_one, brew_no_available_formula_two,
|
|
|
|
brew_no_available_formula_three, brew_already_installed,
|
2015-04-23 17:42:03 +09:00
|
|
|
brew_install_no_argument):
|
2022-07-02 15:06:00 +02:00
|
|
|
assert match(Command('brew install giss',
|
|
|
|
brew_no_available_formula_one))
|
|
|
|
assert match(Command('brew install elasticserar',
|
|
|
|
brew_no_available_formula_two))
|
|
|
|
assert match(Command('brew install gitt',
|
|
|
|
brew_no_available_formula_three))
|
2015-04-25 02:35:26 +02:00
|
|
|
assert not match(Command('brew install git',
|
2017-08-31 17:58:56 +02:00
|
|
|
brew_already_installed))
|
|
|
|
assert not match(Command('brew install', brew_install_no_argument))
|
2015-04-23 17:42:03 +09:00
|
|
|
|
|
|
|
|
2022-07-02 15:06:00 +02:00
|
|
|
def test_get_new_command(brew_no_available_formula_one, brew_no_available_formula_two,
|
|
|
|
brew_no_available_formula_three):
|
|
|
|
assert get_new_command(Command('brew install giss',
|
|
|
|
brew_no_available_formula_one))\
|
|
|
|
== ['brew install gist']
|
|
|
|
assert get_new_command(Command('brew install elasticsear',
|
|
|
|
brew_no_available_formula_two))\
|
|
|
|
== ['brew install elasticsearch', 'brew install elasticsearch@6']
|
|
|
|
assert get_new_command(Command('brew install gitt',
|
|
|
|
brew_no_available_formula_three))\
|
|
|
|
== ['brew install git', 'brew install gitg', 'brew install gist']
|
2015-04-23 17:42:03 +09:00
|
|
|
|
2015-04-25 02:35:26 +02:00
|
|
|
assert get_new_command(Command('brew install aa',
|
2022-07-02 15:06:00 +02:00
|
|
|
brew_no_available_formula_one))\
|
2015-10-17 18:45:29 -03:00
|
|
|
!= 'brew install aha'
|