2016-03-25 23:40:17 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
2016-10-11 23:08:55 -04:00
|
|
|
# Copyright (C) 2015-2016 YouCompleteMe contributors
|
2015-08-28 10:26:18 -04:00
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
2017-03-09 09:57:27 -05:00
|
|
|
# Not installing aliases from python-future; it's unreliable and slow.
|
2016-02-27 19:12:24 -05:00
|
|
|
from builtins import * # noqa
|
|
|
|
|
2016-10-14 05:00:57 -04:00
|
|
|
from ycm.tests.test_utils import MockVimModule
|
2015-12-21 14:38:56 -05:00
|
|
|
MockVimModule()
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
import contextlib
|
|
|
|
from mock import MagicMock, DEFAULT, patch
|
|
|
|
from nose.tools import eq_, ok_
|
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
from ycm import vimsupport
|
2016-07-14 16:49:29 -04:00
|
|
|
from ycmd.utils import ToBytes
|
2018-03-26 21:22:31 -04:00
|
|
|
from ycm.client.completion_request import ( CompletionRequest,
|
|
|
|
_FilterToMatchingCompletions,
|
|
|
|
_GetRequiredNamespaceImport )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
def CompleteItemIs( word, abbr = None, menu = None,
|
|
|
|
info = None, kind = None, **kwargs ):
|
|
|
|
item = {
|
|
|
|
'word': ToBytes( word ),
|
|
|
|
'abbr': ToBytes( abbr ),
|
|
|
|
'menu': ToBytes( menu ),
|
|
|
|
'info': ToBytes( info ),
|
|
|
|
'kind': ToBytes( kind ),
|
|
|
|
}
|
|
|
|
item.update( **kwargs )
|
|
|
|
return item
|
|
|
|
|
2015-12-21 14:38:56 -05:00
|
|
|
|
|
|
|
def GetVariableValue_CompleteItemIs( word, abbr = None, menu = None,
|
2018-02-10 18:48:22 -05:00
|
|
|
info = None, kind = None, **kwargs ):
|
2015-12-21 14:38:56 -05:00
|
|
|
def Result( variable ):
|
|
|
|
if variable == 'v:completed_item':
|
2018-02-10 18:48:22 -05:00
|
|
|
return CompleteItemIs( word, abbr, menu, info, kind, **kwargs )
|
2016-02-28 23:04:12 -05:00
|
|
|
return DEFAULT
|
2015-12-21 14:38:56 -05:00
|
|
|
return MagicMock( side_effect = Result )
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
def BuildCompletion( insertion_text = 'Test',
|
|
|
|
menu_text = None,
|
|
|
|
extra_menu_info = None,
|
|
|
|
detailed_info = None,
|
|
|
|
kind = None,
|
|
|
|
extra_data = None ):
|
|
|
|
if extra_data is None:
|
|
|
|
extra_data = {}
|
|
|
|
|
2015-12-21 14:38:56 -05:00
|
|
|
return {
|
2018-02-10 18:48:22 -05:00
|
|
|
'extra_data': extra_data,
|
2015-12-21 14:38:56 -05:00
|
|
|
'insertion_text': insertion_text,
|
|
|
|
'menu_text': menu_text,
|
|
|
|
'extra_menu_info': extra_menu_info,
|
|
|
|
'kind': kind,
|
|
|
|
'detailed_info': detailed_info,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
def BuildCompletionNamespace( namespace = None,
|
|
|
|
insertion_text = 'Test',
|
|
|
|
menu_text = None,
|
|
|
|
extra_menu_info = None,
|
|
|
|
detailed_info = None,
|
|
|
|
kind = None ):
|
|
|
|
return BuildCompletion( insertion_text = insertion_text,
|
|
|
|
menu_text = menu_text,
|
|
|
|
extra_menu_info = extra_menu_info,
|
|
|
|
detailed_info = detailed_info,
|
|
|
|
kind = kind,
|
|
|
|
extra_data = {
|
|
|
|
'required_namespace_import': namespace
|
|
|
|
} )
|
|
|
|
|
|
|
|
|
|
|
|
def BuildCompletionFixIt( fixits,
|
|
|
|
insertion_text = 'Test',
|
|
|
|
menu_text = None,
|
|
|
|
extra_menu_info = None,
|
|
|
|
detailed_info = None,
|
|
|
|
kind = None ):
|
|
|
|
return BuildCompletion( insertion_text = insertion_text,
|
|
|
|
menu_text = menu_text,
|
|
|
|
extra_menu_info = extra_menu_info,
|
|
|
|
detailed_info = detailed_info,
|
|
|
|
kind = kind,
|
|
|
|
extra_data = {
|
|
|
|
'fixits': fixits,
|
|
|
|
} )
|
|
|
|
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@contextlib.contextmanager
|
2018-03-26 21:22:31 -04:00
|
|
|
def _SetupForCsharpCompletionDone( completions ):
|
2016-10-11 16:54:00 -04:00
|
|
|
with patch( 'ycm.vimsupport.InsertNamespace' ):
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
|
|
|
yield request
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@contextlib.contextmanager
|
2018-03-26 21:22:31 -04:00
|
|
|
def _SetUpCompleteDone( completions ):
|
2018-02-10 18:48:22 -05:00
|
|
|
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' ):
|
2018-03-26 21:22:31 -04:00
|
|
|
request = CompletionRequest( None )
|
2018-02-10 18:48:22 -05:00
|
|
|
request.Done = MagicMock( return_value = True )
|
|
|
|
request.RawResponse = MagicMock( return_value = {
|
|
|
|
'completions': completions
|
|
|
|
} )
|
2018-03-26 21:22:31 -04:00
|
|
|
yield request
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompleteDoneHooks_ResultOnCsharp_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
result = list( request._GetCompleteDoneHooks() )
|
|
|
|
eq_( result, [ request._OnCompleteDone_Csharp ] )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'java' ] )
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompleteDoneHooks_ResultOnJava_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
result = list( request._GetCompleteDoneHooks() )
|
2018-03-26 19:20:53 -04:00
|
|
|
eq_( result, [ request._OnCompleteDone_FixIt ] )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'typescript' ] )
|
|
|
|
def GetCompleteDoneHooks_ResultOnTypeScript_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
result = list( request._GetCompleteDoneHooks() )
|
|
|
|
eq_( result, [ request._OnCompleteDone_FixIt ] )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
result = request._GetCompleteDoneHooks()
|
|
|
|
eq_( len( list( result ) ), 0 )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
2018-03-26 21:22:31 -04:00
|
|
|
def OnCompleteDone_WithActionCallsIt_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
request.Done = MagicMock( return_value = True )
|
2016-10-11 16:54:00 -04:00
|
|
|
action = MagicMock()
|
2018-03-26 21:22:31 -04:00
|
|
|
request._complete_done_hooks[ 'ycmtest' ] = action
|
|
|
|
request.OnCompleteDone()
|
2016-10-11 16:54:00 -04:00
|
|
|
ok_( action.called )
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
2018-03-26 21:22:31 -04:00
|
|
|
def OnCompleteDone_NoActionNoError_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
request.Done = MagicMock( return_value = True )
|
|
|
|
request._OnCompleteDone_Csharp = MagicMock()
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt = MagicMock()
|
2018-03-26 21:22:31 -04:00
|
|
|
request.OnCompleteDone()
|
|
|
|
request._OnCompleteDone_Csharp.assert_not_called()
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt.assert_not_called()
|
2018-03-26 21:22:31 -04:00
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
|
|
|
def OnCompleteDone_NoActionIfNotDone_test( *args ):
|
|
|
|
request = CompletionRequest( None )
|
|
|
|
request.Done = MagicMock( return_value = False )
|
|
|
|
action = MagicMock()
|
|
|
|
request._complete_done_hooks[ 'ycmtest' ] = action
|
|
|
|
request.OnCompleteDone()
|
|
|
|
action.assert_not_called()
|
2016-10-11 16:54:00 -04:00
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
|
|
|
|
def FilterToCompletedCompletions_MatchIsReturned_test():
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
result = _FilterToMatchingCompletions( CompleteItemIs( 'Test' ), completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def FilterToCompletedCompletions_ShortTextDoesntRaise_test():
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
result = _FilterToMatchingCompletions( CompleteItemIs( 'A' ), completions )
|
2018-03-26 21:22:31 -04:00
|
|
|
eq_( list( result ), [] )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def FilterToCompletedCompletions_ExactMatchIsReturned_test():
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
result = _FilterToMatchingCompletions( CompleteItemIs( 'Test' ), completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def FilterToCompletedCompletions_NonMatchIsntReturned_test():
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
result = _FilterToMatchingCompletions( CompleteItemIs( ' Quote' ),
|
2018-03-26 21:22:31 -04:00
|
|
|
completions )
|
2018-03-26 21:22:31 -04:00
|
|
|
eq_( list( result ), [] )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def FilterToCompletedCompletions_Unicode_test():
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = '†es†' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
result = _FilterToMatchingCompletions( CompleteItemIs( '†es†' ),
|
2018-03-26 21:22:31 -04:00
|
|
|
completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test():
|
|
|
|
eq_( _GetRequiredNamespaceImport( {} ), None )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test():
|
2016-10-11 16:54:00 -04:00
|
|
|
namespace = 'A_NAMESPACE'
|
2018-03-26 21:22:31 -04:00
|
|
|
eq_( _GetRequiredNamespaceImport( BuildCompletionNamespace( namespace ) ),
|
|
|
|
namespace )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Te' ) )
|
2017-05-17 05:43:02 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_test(
|
2018-03-26 21:22:31 -04:00
|
|
|
*args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( None ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(), [] )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_test( *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( *info ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
2016-10-11 16:54:00 -04:00
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
2018-03-26 21:22:31 -04:00
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(), completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_test(): # noqa
|
2016-10-11 16:54:00 -04:00
|
|
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( *info ),
|
2016-10-11 16:54:00 -04:00
|
|
|
BuildCompletion( insertion_text = 'TestTest' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
2016-10-11 16:54:00 -04:00
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
2018-03-26 21:22:31 -04:00
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(), [ completions[ 0 ] ] )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNoExactMatchesAndPartial_test(): # noqa
|
2016-10-11 16:54:00 -04:00
|
|
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
|
|
|
completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
|
|
|
|
BuildCompletion( insertion_text = 'TestTest' ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
2016-10-11 16:54:00 -04:00
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
2018-03-26 21:22:31 -04:00
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(), [] )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_test( *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( None ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(), completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='0' ) )
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_UseUserData0_test( *args ):
|
|
|
|
# Identical completions but we specify the first one via user_data.
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionNamespace( 'namespace1' ),
|
|
|
|
BuildCompletionNamespace( 'namespace2' )
|
|
|
|
]
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(),
|
|
|
|
[ BuildCompletionNamespace( 'namespace1' ) ] )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='1' ) )
|
2018-03-26 21:22:31 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_UseUserData1_test( *args ):
|
|
|
|
# Identical completions but we specify the second one via user_data.
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionNamespace( 'namespace1' ),
|
|
|
|
BuildCompletionNamespace( 'namespace2' )
|
|
|
|
]
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(),
|
|
|
|
[ BuildCompletionNamespace( 'namespace2' ) ] )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
2018-03-26 21:22:31 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='' ) )
|
|
|
|
def GetCompletionsUserMayHaveCompleted_EmptyUserData_test( *args ):
|
|
|
|
# Identical completions but none is selected.
|
|
|
|
completions = [
|
|
|
|
BuildCompletionNamespace( 'namespace1' ),
|
|
|
|
BuildCompletionNamespace( 'namespace2' )
|
|
|
|
]
|
|
|
|
|
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
eq_( request._GetCompletionsUserMayHaveCompleted(), [] )
|
|
|
|
|
|
|
|
|
2017-05-17 05:43:02 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
2018-03-26 21:22:31 -04:00
|
|
|
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( *args ):
|
|
|
|
with _SetupForCsharpCompletionDone( [] ) as request:
|
|
|
|
request._OnCompleteDone_Csharp()
|
2016-10-11 16:54:00 -04:00
|
|
|
ok_( not vimsupport.InsertNamespace.called )
|
|
|
|
|
|
|
|
|
2017-05-17 05:43:02 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
2016-10-11 16:54:00 -04:00
|
|
|
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
|
2018-03-26 21:22:31 -04:00
|
|
|
*args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( None ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
request._OnCompleteDone_Csharp()
|
2016-10-11 16:54:00 -04:00
|
|
|
ok_( not vimsupport.InsertNamespace.called )
|
|
|
|
|
|
|
|
|
2017-05-17 05:43:02 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
2018-03-26 21:22:31 -04:00
|
|
|
def PostCompleteCsharp_ValueDoesInsertNamespace_test( *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
namespace = 'A_NAMESPACE'
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( namespace ) ]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
request._OnCompleteDone_Csharp()
|
2016-10-11 16:54:00 -04:00
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace )
|
|
|
|
|
|
|
|
|
2017-05-17 05:43:02 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
2016-10-11 16:54:00 -04:00
|
|
|
@patch( 'ycm.vimsupport.PresentDialog', return_value = 1 )
|
2018-03-26 21:22:31 -04:00
|
|
|
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
namespace = 'A_NAMESPACE'
|
|
|
|
namespace2 = 'ANOTHER_NAMESPACE'
|
|
|
|
completions = [
|
2018-02-10 18:48:22 -05:00
|
|
|
BuildCompletionNamespace( namespace ),
|
|
|
|
BuildCompletionNamespace( namespace2 ),
|
2016-10-11 16:54:00 -04:00
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetupForCsharpCompletionDone( completions ) as request:
|
|
|
|
request._OnCompleteDone_Csharp()
|
2016-10-11 16:54:00 -04:00
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
2018-03-26 19:20:53 -04:00
|
|
|
def PostCompleteFixIt_ApplyFixIt_NoFixIts_test( replace_chunks, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [] )
|
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt()
|
2018-02-10 18:48:22 -05:00
|
|
|
replace_chunks.assert_not_called()
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
2018-03-26 19:20:53 -04:00
|
|
|
def PostCompleteFixIt_ApplyFixIt_EmptyFixIt_test( replace_chunks, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': [] } ] )
|
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt()
|
2018-03-26 21:22:31 -04:00
|
|
|
replace_chunks.assert_called_once_with( [], silent = True )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
2018-03-26 19:20:53 -04:00
|
|
|
def PostCompleteFixIt_ApplyFixIt_NoFixIt_test( replace_chunks, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
2018-05-29 19:00:49 -04:00
|
|
|
BuildCompletion()
|
2018-02-10 18:48:22 -05:00
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt()
|
2018-02-10 18:48:22 -05:00
|
|
|
replace_chunks.assert_not_called()
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
2018-03-26 19:20:53 -04:00
|
|
|
def PostCompleteFixIt_ApplyFixIt_PickFirst_test( replace_chunks, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'one' } ] ),
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'two' } ] ),
|
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt()
|
2018-03-26 21:22:31 -04:00
|
|
|
replace_chunks.assert_called_once_with( 'one', silent = True )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='0' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
2018-03-26 19:20:53 -04:00
|
|
|
def PostCompleteFixIt_ApplyFixIt_PickFirstUserData_test( replace_chunks,
|
|
|
|
*args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'one' } ] ),
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'two' } ] ),
|
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt()
|
2018-03-26 21:22:31 -04:00
|
|
|
replace_chunks.assert_called_once_with( 'one', silent = True )
|
2018-02-10 18:48:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='1' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
2018-03-26 19:20:53 -04:00
|
|
|
def PostCompleteFixIt_ApplyFixIt_PickSecond_test( replace_chunks, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'one' } ] ),
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'two' } ] ),
|
|
|
|
]
|
2018-03-26 21:22:31 -04:00
|
|
|
with _SetUpCompleteDone( completions ) as request:
|
2018-03-26 19:20:53 -04:00
|
|
|
request._OnCompleteDone_FixIt()
|
2018-03-26 21:22:31 -04:00
|
|
|
replace_chunks.assert_called_once_with( 'two', silent = True )
|