From 94e70b394e10709478ab91ced2dd4649d6e22322 Mon Sep 17 00:00:00 2001 From: micbou Date: Sat, 1 Dec 2018 23:58:34 +0100 Subject: [PATCH] Fix candidate insertion adjustment The abbr field is always defined so we need to check its emptiness when adjusting the candidates insertion text. --- python/ycm/base.py | 2 +- python/ycm/tests/base_test.py | 73 ++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/python/ycm/base.py b/python/ycm/base.py index aa4933a1..8135ee06 100644 --- a/python/ycm/base.py +++ b/python/ycm/base.py @@ -103,7 +103,7 @@ def AdjustCandidateInsertionText( candidates ): for candidate in candidates: new_candidate = candidate.copy() - if 'abbr' not in new_candidate: + if not new_candidate[ 'abbr' ]: new_candidate[ 'abbr' ] = new_candidate[ 'word' ] new_candidate[ 'word' ] = NewCandidateInsertionText( diff --git a/python/ycm/tests/base_test.py b/python/ycm/tests/base_test.py index a7249b61..ff972ceb 100644 --- a/python/ycm/tests/base_test.py +++ b/python/ycm/tests/base_test.py @@ -56,75 +56,78 @@ def MockTextAfterCursor( text ): def AdjustCandidateInsertionText_Basic_test(): with MockTextAfterCursor( 'bar' ): - eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_ParenInTextAfterCursor_test(): with MockTextAfterCursor( 'bar(zoo' ): - eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_PlusInTextAfterCursor_test(): with MockTextAfterCursor( 'bar+zoo' ): - eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_WhitespaceInTextAfterCursor_test(): with MockTextAfterCursor( 'bar zoo' ): - eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_MoreThanWordMatchingAfterCursor_test(): with MockTextAfterCursor( 'bar.h' ): - eq_( [ { 'abbr': 'foobar.h', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar.h' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar.h' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar.h', 'abbr': '' } ] ) ) with MockTextAfterCursor( 'bar(zoo' ): - eq_( [ { 'abbr': 'foobar(zoo', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar(zoo' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar(zoo' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar(zoo', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_NotSuffix_test(): with MockTextAfterCursor( 'bar' ): - eq_( [ { 'abbr': 'foofoo', 'word': 'foofoo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foofoo' } ] ) ) + eq_( [ { 'word': 'foofoo', 'abbr': 'foofoo' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foofoo', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_NothingAfterCursor_test(): with MockTextAfterCursor( '' ): - eq_( [ { 'word': 'foofoo' }, - { 'word': 'zobar' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foofoo' }, - { 'word': 'zobar' } ] ) ) + eq_( [ { 'word': 'foofoo', 'abbr': '' }, + { 'word': 'zobar', 'abbr': '' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foofoo', 'abbr': '' }, + { 'word': 'zobar', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_MultipleStrings_test(): with MockTextAfterCursor( 'bar' ): - eq_( [ { 'abbr': 'foobar', 'word': 'foo' }, - { 'abbr': 'zobar', 'word': 'zo' }, - { 'abbr': 'qbar', 'word': 'q' }, - { 'abbr': 'bar', 'word': '' }, ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar' }, - { 'word': 'zobar' }, - { 'word': 'qbar' }, - { 'word': 'bar' } ] ) ) - - -def AdjustCandidateInsertionText_DictInput_test(): - with MockTextAfterCursor( 'bar' ): - eq_( [ { 'abbr': 'foobar', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( [ { 'word': 'foobar' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': 'foobar' }, + { 'word': 'zo', 'abbr': 'zobar' }, + { 'word': 'q', 'abbr': 'qbar' }, + { 'word': '', 'abbr': 'bar' }, ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar', 'abbr': '' }, + { 'word': 'zobar', 'abbr': '' }, + { 'word': 'qbar', 'abbr': '' }, + { 'word': 'bar', 'abbr': '' } ] ) ) def AdjustCandidateInsertionText_DontTouchAbbr_test(): with MockTextAfterCursor( 'bar' ): - eq_( [ { 'abbr': '1234', 'word': 'foo' } ], - base.AdjustCandidateInsertionText( - [ { 'abbr': '1234', 'word': 'foobar' } ] ) ) + eq_( [ { 'word': 'foo', 'abbr': '1234' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar', 'abbr': '1234' } ] ) ) def OverlapLength_Basic_test():