1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 14:48:49 +00:00

Added persian letters rule for converting those letters to english

This commit is contained in:
Hossain Alhaidari 2018-10-21 21:14:53 +03:30
parent d226b8f258
commit a725b4c561
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import pytest
from thefuck.types import Command
from thefuck.rules.chmod_x import match, get_new_command
@pytest.mark.parametrize('command', [
Command('حصی', 'command not found: حصی'),
Command('مس -مش', 'command not found: مس'),
Command('لهف سفشفعس', 'command not found: لهف'),
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('حصی', ''), 'pwd'),
(Command('مس -مش', ''), 'ls -la'),
(Command('لهف سفشفعس', ''), 'git status'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command

View File

@ -0,0 +1,16 @@
persian_letters = ('ض', 'ص', 'ث', 'ق', 'ف', 'غ', 'ع', 'ه', 'خ', 'ح', 'ج', 'چ', 'ش', 'س', 'ی', 'ب',
'ل', 'ا', 'ت', 'ن', 'م', 'ک', 'گ', 'ظ', 'ط', 'ز', 'ر', 'ذ', 'د', 'پ', 'و')
english_letters = ('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 'a', 's', 'd', 'f',
'g', 'h', 'j', 'k', 'l', ';', "'", 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',')
def match(command):
return (command.script.startswith(persian_letters)
and 'command not found' in command.output.lower())
def get_new_command(command):
script = command.script
for i, letter in enumerate(persian_letters):
script = script.replace(letter, english_letters[i])
return script