Accept single-edit typos in correction gates
difflib's SequenceMatcher underrates adjacent transpositions, so the flagship examples (gti->git 0.667, greo->grep 0.75, psuh->push 0.75) fell below the 0.8 ratio gates and were declined. Per the plan amendment, the token and candidate gates in the history resolver, guess_from_path and the help resolver additionally accept a first-char-equal single edit (one substitution, insertion, deletion or adjacent transposition; new thefuck/typo.py), with the ratio cutoffs, the exact-one-candidate rule and the 0.79 boundary (edit distance >= 2) unchanged.
This commit is contained in:
@@ -180,6 +180,22 @@ class TestGuessFromPathSegments(object):
|
||||
assert (learned.guess_from_path('gi psuh | gre -i foo')
|
||||
== 'git psuh | grep -i foo')
|
||||
|
||||
def test_fixes_single_edit_typos_under_cutoff(self, learned,
|
||||
path_bins):
|
||||
# gti -> git scores 2 * 2 / 6 = 0.667 and greo -> grep scores
|
||||
# 2 * 3 / 8 = 0.75, both under GUESS_CUTOFF; each is still a
|
||||
# first-char-equal single edit with one executable match.
|
||||
path_bins(executables=['git', 'grep', 'sed'])
|
||||
assert (learned.guess_from_path('gti psuh | greo -i foo')
|
||||
== 'git psuh | grep -i foo')
|
||||
|
||||
def test_declines_single_edit_ambiguity(self, learned, path_bins):
|
||||
# gti is one edit from both git (transposition) and gui
|
||||
# (substitution), each scoring 2 * 2 / 6 = 0.667, so two
|
||||
# candidates survive and the segment is skipped.
|
||||
path_bins(executables=['git', 'gui'])
|
||||
assert learned.guess_from_path('gti psuh') is None
|
||||
|
||||
def test_fixes_only_segment_with_unknown_head(self, learned, path_bins):
|
||||
path_bins(executables=['git', 'grep', 'sed'], existing=['git'])
|
||||
assert (learned.guess_from_path('git psuh | gre -i foo')
|
||||
|
||||
Reference in New Issue
Block a user