2016-10-03 00:30:48 -04:00
|
|
|
import pytest
|
2016-10-05 10:52:24 -04:00
|
|
|
from thefuck.rules.ag_literal import get_new_command, match
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2016-10-03 00:30:48 -04:00
|
|
|
|
|
|
|
|
2016-10-05 10:52:24 -04:00
|
|
|
@pytest.fixture
|
2017-08-31 17:58:56 +02:00
|
|
|
def output():
|
2016-10-05 10:52:24 -04:00
|
|
|
return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n'
|
|
|
|
'If you meant to search for a literal string, run ag with -Q\n')
|
2016-10-03 00:30:48 -04:00
|
|
|
|
2016-10-05 10:32:14 -04:00
|
|
|
|
2018-10-30 20:56:55 +01:00
|
|
|
@pytest.mark.parametrize('script', ['ag \\('])
|
2017-08-31 17:58:56 +02:00
|
|
|
def test_match(script, output):
|
|
|
|
assert match(Command(script, output))
|
2016-10-03 00:30:48 -04:00
|
|
|
|
|
|
|
|
2016-10-05 10:52:24 -04:00
|
|
|
@pytest.mark.parametrize('script', ['ag foo'])
|
|
|
|
def test_not_match(script):
|
2017-08-31 17:58:56 +02:00
|
|
|
assert not match(Command(script, ''))
|
2016-10-03 00:30:48 -04:00
|
|
|
|
|
|
|
|
2016-10-05 10:52:24 -04:00
|
|
|
@pytest.mark.parametrize('script, new_cmd', [
|
2018-10-30 20:56:55 +01:00
|
|
|
('ag \\(', 'ag -Q \\(')])
|
2017-08-31 17:58:56 +02:00
|
|
|
def test_get_new_command(script, new_cmd, output):
|
|
|
|
assert get_new_command((Command(script, output))) == new_cmd
|