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
|
2015-08-28 10:26:18 -04:00
|
|
|
from hamcrest import assert_that, empty
|
2016-02-28 23:04:12 -05:00
|
|
|
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-10-11 16:54:00 -04:00
|
|
|
from ycm.tests import YouCompleteMeInstance
|
2016-07-14 16:49:29 -04:00
|
|
|
from ycmd.utils import ToBytes
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
from ycm.youcompleteme import _CompleteDoneHook_CSharp
|
|
|
|
from ycm.youcompleteme import _CompleteDoneHook_Java
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
def _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
with patch( 'ycm.vimsupport.InsertNamespace' ):
|
2018-02-10 18:48:22 -05:00
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
2016-10-11 16:54:00 -04:00
|
|
|
yield
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def _SetUpCompleteDone( ycm, completions ):
|
|
|
|
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' ):
|
|
|
|
request = MagicMock()
|
|
|
|
request.Done = MagicMock( return_value = True )
|
|
|
|
request.RawResponse = MagicMock( return_value = {
|
|
|
|
'completions': completions
|
|
|
|
} )
|
|
|
|
ycm._latest_completion_request = request
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetCompleteDoneHooks_ResultOnCsharp_test( ycm, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
result = list( ycm.GetCompleteDoneHooks() )
|
|
|
|
eq_( [ _CompleteDoneHook_CSharp ], result )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'java' ] )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetCompleteDoneHooks_ResultOnJava_test( ycm, *args ):
|
|
|
|
result = list( ycm.GetCompleteDoneHooks() )
|
|
|
|
eq_( [ _CompleteDoneHook_Java ], result )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
2016-10-11 16:54:00 -04:00
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( ycm, *args ):
|
|
|
|
result = ycm.GetCompleteDoneHooks()
|
|
|
|
eq_( 0, len( list( result ) ) )
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
2016-10-11 16:54:00 -04:00
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def OnCompleteDone_WithActionCallsIt_test( ycm, *args ):
|
|
|
|
action = MagicMock()
|
2018-02-10 18:48:22 -05:00
|
|
|
ycm._complete_done_hooks[ 'ycmtest' ] = action
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm.OnCompleteDone()
|
|
|
|
ok_( action.called )
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
|
2016-10-11 16:54:00 -04:00
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def OnCompleteDone_NoActionNoError_test( ycm, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
with patch.object( ycm, '_OnCompleteDone_Csharp' ) as csharp:
|
|
|
|
with patch.object( ycm, '_OnCompleteDone_Java' ) as java:
|
|
|
|
ycm.OnCompleteDone()
|
|
|
|
csharp.assert_not_called()
|
|
|
|
java.assert_not_called()
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def FilterToCompletedCompletions_MatchIsReturned_test( ycm, *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._FilterToMatchingCompletions( CompleteItemIs( 'Test' ),
|
|
|
|
completions,
|
|
|
|
False )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def FilterToCompletedCompletions_ShortTextDoesntRaise_test( ycm, *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
ycm._FilterToMatchingCompletions( CompleteItemIs( 'A' ),
|
|
|
|
completions,
|
|
|
|
False )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def FilterToCompletedCompletions_ExactMatchIsReturned_test( ycm, *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._FilterToMatchingCompletions( CompleteItemIs( 'Test' ),
|
|
|
|
completions,
|
|
|
|
False )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def FilterToCompletedCompletions_NonMatchIsntReturned_test( ycm, *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = 'A' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._FilterToMatchingCompletions( CompleteItemIs( ' Quote' ),
|
|
|
|
completions,
|
|
|
|
False )
|
2016-10-11 16:54:00 -04:00
|
|
|
assert_that( list( result ), empty() )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def FilterToCompletedCompletions_Unicode_test( ycm, *args ):
|
2016-10-11 16:54:00 -04:00
|
|
|
completions = [ BuildCompletion( insertion_text = '†es†' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._FilterToMatchingCompletions( CompleteItemIs( '†es†' ),
|
|
|
|
completions,
|
|
|
|
False )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_MatchIsReturned_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
CompleteItemIs( 'Te' ),
|
|
|
|
completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( result, True )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_ShortTextDoesntRaise_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
completions = [ BuildCompletion( insertion_text = 'AAA' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
ycm._HasCompletionsThatCouldBeCompletedWithMoreText( CompleteItemIs( 'X' ),
|
|
|
|
completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_ExactMatchIsntReturned_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
completions = [ BuildCompletion( insertion_text = 'Test' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
CompleteItemIs( 'Test' ),
|
|
|
|
completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( result, False )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NonMatchIsntReturned_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
completions = [ BuildCompletion( insertion_text = "A" ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
CompleteItemIs( ' Quote' ),
|
|
|
|
completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( result, False )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_Unicode_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ]
|
2018-02-10 18:48:22 -05:00
|
|
|
result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
CompleteItemIs( 'Uniç' ),
|
|
|
|
completions )
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( result, True )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( ycm ):
|
|
|
|
eq_( None, ycm._GetRequiredNamespaceImport( {} ) )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( ycm ):
|
|
|
|
namespace = 'A_NAMESPACE'
|
|
|
|
eq_( namespace, ycm._GetRequiredNamespaceImport(
|
2018-02-10 18:48:22 -05:00
|
|
|
BuildCompletionNamespace( namespace )
|
2016-10-11 16:54:00 -04:00
|
|
|
) )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( ycm ):
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, [] ):
|
|
|
|
ycm._latest_completion_request.Done = MagicMock( return_value = False )
|
|
|
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Te' ) )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( None ) ]
|
2016-10-11 16:54:00 -04:00
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_test(
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
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
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
|
|
|
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_test( # noqa
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
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' ) ]
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
|
|
|
eq_( [ completions[ 0 ] ], ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNoExactMatchesAndPartial_test( # noqa
|
2016-10-11 16:54:00 -04:00
|
|
|
ycm, *args ):
|
|
|
|
info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ]
|
|
|
|
completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
|
|
|
|
BuildCompletion( insertion_text = 'TestTest' ) ]
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
|
|
|
eq_( [], ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@YouCompleteMeInstance()
|
2017-05-17 05:43:02 -04:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_test( ycm, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( None ) ]
|
2016-10-11 16:54:00 -04:00
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
2018-02-10 18:48:22 -05:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='0' ) )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetCompletionsUserMayHaveCompleted_UseUserData0_test( ycm, *args ):
|
|
|
|
# identical completions but we specify the first one via user_data
|
|
|
|
completions = [
|
|
|
|
BuildCompletionNamespace( 'namespace1' ),
|
|
|
|
BuildCompletionNamespace( 'namespace2' )
|
|
|
|
]
|
|
|
|
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
eq_( [ BuildCompletionNamespace( 'namespace1' ) ],
|
|
|
|
ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='1' ) )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def GetCompletionsUserMayHaveCompleted_UseUserData1_test( ycm, *args ):
|
|
|
|
# identical completions but we specify the second one via user_data
|
|
|
|
completions = [
|
|
|
|
BuildCompletionNamespace( 'namespace1' ),
|
|
|
|
BuildCompletionNamespace( 'namespace2' )
|
|
|
|
]
|
|
|
|
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
eq_( [ BuildCompletionNamespace( 'namespace2' ) ],
|
|
|
|
ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
|
|
|
|
2017-05-17 05:43:02 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
2016-10-11 16:54:00 -04:00
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( ycm, *args ):
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, [] ):
|
|
|
|
ycm._OnCompleteDone_Csharp()
|
|
|
|
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
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
|
|
|
|
ycm, *args ):
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( None ) ]
|
2016-10-11 16:54:00 -04:00
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Csharp()
|
|
|
|
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
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteCsharp_ValueDoesInsertNamespace_test( ycm, *args ):
|
|
|
|
namespace = 'A_NAMESPACE'
|
2018-02-10 18:48:22 -05:00
|
|
|
completions = [ BuildCompletionNamespace( namespace ) ]
|
2016-10-11 16:54:00 -04:00
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Csharp()
|
|
|
|
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 )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( ycm, *args ):
|
|
|
|
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
|
|
|
]
|
|
|
|
with _SetupForCsharpCompletionDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Csharp()
|
|
|
|
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' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteJava_ApplyFixIt_NoFixIts_test( ycm, replace_chunks, *args ):
|
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [] )
|
|
|
|
]
|
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Java()
|
|
|
|
replace_chunks.assert_not_called()
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteJava_ApplyFixIt_EmptyFixIt_test( ycm, replace_chunks, *args ):
|
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': [] } ] )
|
|
|
|
]
|
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Java()
|
|
|
|
replace_chunks.assert_called_once_with( [], silent=True )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteJava_ApplyFixIt_NoFixIt_test( ycm, replace_chunks, *args ):
|
|
|
|
completions = [
|
|
|
|
BuildCompletion( )
|
|
|
|
]
|
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Java()
|
|
|
|
replace_chunks.assert_not_called()
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteJava_ApplyFixIt_PickFirst_test( ycm, replace_chunks, *args ):
|
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'one' } ] ),
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'two' } ] ),
|
|
|
|
]
|
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Java()
|
|
|
|
replace_chunks.assert_called_once_with( 'one', silent=True )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='0' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteJava_ApplyFixIt_PickFirstUserData_test( ycm,
|
|
|
|
replace_chunks,
|
|
|
|
*args ):
|
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'one' } ] ),
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'two' } ] ),
|
|
|
|
]
|
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Java()
|
|
|
|
replace_chunks.assert_called_once_with( 'one', silent=True )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test', user_data='1' ) )
|
|
|
|
@patch( 'ycm.vimsupport.ReplaceChunks' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def PostCompleteJava_ApplyFixIt_PickSecond_test( ycm, replace_chunks, *args ):
|
|
|
|
completions = [
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'one' } ] ),
|
|
|
|
BuildCompletionFixIt( [ { 'chunks': 'two' } ] ),
|
|
|
|
]
|
|
|
|
with _SetUpCompleteDone( ycm, completions ):
|
|
|
|
ycm._OnCompleteDone_Java()
|
|
|
|
replace_chunks.assert_called_once_with( 'two', silent=True )
|