Testing AG Command Literal Search Transformation in thefuck
This test suite validates the ag_literal rule functionality in thefuck project, focusing on handling literal string searches with the ag command when regex patterns fail. The tests ensure proper command transformation for escaped characters.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nvbn/thefuck
tests/rules/test_ag_literal.py
import pytest
from thefuck.rules.ag_literal import get_new_command, match
from thefuck.types import Command
@pytest.fixture
def output():
return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )
'
'If you meant to search for a literal string, run ag with -Q
')
@pytest.mark.parametrize('script', ['ag \\('])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script', ['ag foo'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, new_cmd', [
('ag \\(', 'ag -Q \\(')])
def test_get_new_command(script, new_cmd, output):
assert get_new_command((Command(script, output))) == new_cmd