Fix candidate insertion adjustment

The abbr field is always defined so we need to check its emptiness when
adjusting the candidates insertion text.
This commit is contained in:
micbou 2018-12-01 23:58:34 +01:00
parent 75bf1738dc
commit 94e70b394e
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
2 changed files with 39 additions and 36 deletions

View File

@ -103,7 +103,7 @@ def AdjustCandidateInsertionText( candidates ):
for candidate in candidates: for candidate in candidates:
new_candidate = candidate.copy() new_candidate = candidate.copy()
if 'abbr' not in new_candidate: if not new_candidate[ 'abbr' ]:
new_candidate[ 'abbr' ] = new_candidate[ 'word' ] new_candidate[ 'abbr' ] = new_candidate[ 'word' ]
new_candidate[ 'word' ] = NewCandidateInsertionText( new_candidate[ 'word' ] = NewCandidateInsertionText(

View File

@ -56,75 +56,78 @@ def MockTextAfterCursor( text ):
def AdjustCandidateInsertionText_Basic_test(): def AdjustCandidateInsertionText_Basic_test():
with MockTextAfterCursor( 'bar' ): with MockTextAfterCursor( 'bar' ):
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foobar', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_ParenInTextAfterCursor_test(): def AdjustCandidateInsertionText_ParenInTextAfterCursor_test():
with MockTextAfterCursor( 'bar(zoo' ): with MockTextAfterCursor( 'bar(zoo' ):
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foobar', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_PlusInTextAfterCursor_test(): def AdjustCandidateInsertionText_PlusInTextAfterCursor_test():
with MockTextAfterCursor( 'bar+zoo' ): with MockTextAfterCursor( 'bar+zoo' ):
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foobar', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_WhitespaceInTextAfterCursor_test(): def AdjustCandidateInsertionText_WhitespaceInTextAfterCursor_test():
with MockTextAfterCursor( 'bar zoo' ): with MockTextAfterCursor( 'bar zoo' ):
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foobar', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_MoreThanWordMatchingAfterCursor_test(): def AdjustCandidateInsertionText_MoreThanWordMatchingAfterCursor_test():
with MockTextAfterCursor( 'bar.h' ): with MockTextAfterCursor( 'bar.h' ):
eq_( [ { 'abbr': 'foobar.h', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': 'foobar.h' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar.h' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foobar.h', 'abbr': '' } ] ) )
with MockTextAfterCursor( 'bar(zoo' ): with MockTextAfterCursor( 'bar(zoo' ):
eq_( [ { 'abbr': 'foobar(zoo', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': 'foobar(zoo' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar(zoo' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foobar(zoo', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_NotSuffix_test(): def AdjustCandidateInsertionText_NotSuffix_test():
with MockTextAfterCursor( 'bar' ): with MockTextAfterCursor( 'bar' ):
eq_( [ { 'abbr': 'foofoo', 'word': 'foofoo' } ], eq_( [ { 'word': 'foofoo', 'abbr': 'foofoo' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foofoo' } ] ) ) base.AdjustCandidateInsertionText( [
{ 'word': 'foofoo', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_NothingAfterCursor_test(): def AdjustCandidateInsertionText_NothingAfterCursor_test():
with MockTextAfterCursor( '' ): with MockTextAfterCursor( '' ):
eq_( [ { 'word': 'foofoo' }, eq_( [ { 'word': 'foofoo', 'abbr': '' },
{ 'word': 'zobar' } ], { 'word': 'zobar', 'abbr': '' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foofoo' }, base.AdjustCandidateInsertionText( [
{ 'word': 'zobar' } ] ) ) { 'word': 'foofoo', 'abbr': '' },
{ 'word': 'zobar', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_MultipleStrings_test(): def AdjustCandidateInsertionText_MultipleStrings_test():
with MockTextAfterCursor( 'bar' ): with MockTextAfterCursor( 'bar' ):
eq_( [ { 'abbr': 'foobar', 'word': 'foo' }, eq_( [ { 'word': 'foo', 'abbr': 'foobar' },
{ 'abbr': 'zobar', 'word': 'zo' }, { 'word': 'zo', 'abbr': 'zobar' },
{ 'abbr': 'qbar', 'word': 'q' }, { 'word': 'q', 'abbr': 'qbar' },
{ 'abbr': 'bar', 'word': '' }, ], { 'word': '', 'abbr': 'bar' }, ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar' }, base.AdjustCandidateInsertionText( [
{ 'word': 'zobar' }, { 'word': 'foobar', 'abbr': '' },
{ 'word': 'qbar' }, { 'word': 'zobar', 'abbr': '' },
{ 'word': 'bar' } ] ) ) { 'word': 'qbar', 'abbr': '' },
{ 'word': 'bar', 'abbr': '' } ] ) )
def AdjustCandidateInsertionText_DictInput_test():
with MockTextAfterCursor( 'bar' ):
eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ],
base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) )
def AdjustCandidateInsertionText_DontTouchAbbr_test(): def AdjustCandidateInsertionText_DontTouchAbbr_test():
with MockTextAfterCursor( 'bar' ): with MockTextAfterCursor( 'bar' ):
eq_( [ { 'abbr': '1234', 'word': 'foo' } ], eq_( [ { 'word': 'foo', 'abbr': '1234' } ],
base.AdjustCandidateInsertionText( base.AdjustCandidateInsertionText( [
[ { 'abbr': '1234', 'word': 'foobar' } ] ) ) { 'word': 'foobar', 'abbr': '1234' } ] ) )
def OverlapLength_Basic_test(): def OverlapLength_Basic_test():