2015-08-31 12:51:23 -04:00
|
|
|
# Copyright (C) 2015 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
|
|
|
|
from future import standard_library
|
|
|
|
standard_library.install_aliases()
|
|
|
|
from builtins import * # noqa
|
|
|
|
|
2015-12-22 18:28:36 -05:00
|
|
|
from ycm.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
|
|
|
|
from ycm.youcompleteme import YouCompleteMe
|
|
|
|
|
2015-12-21 14:38:56 -05:00
|
|
|
|
|
|
|
def GetVariableValue_CompleteItemIs( word, abbr = None, menu = None,
|
|
|
|
info = None, kind = None ):
|
|
|
|
def Result( variable ):
|
|
|
|
if variable == 'v:completed_item':
|
|
|
|
return {
|
|
|
|
'word': word,
|
|
|
|
'abbr': abbr,
|
|
|
|
'menu': menu,
|
|
|
|
'info': info,
|
|
|
|
'kind': kind,
|
|
|
|
}
|
2016-02-28 23:04:12 -05:00
|
|
|
return DEFAULT
|
2015-12-21 14:38:56 -05:00
|
|
|
return MagicMock( side_effect = Result )
|
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def BuildCompletion( namespace = None, insertion_text = 'Test',
|
|
|
|
menu_text = None, extra_menu_info = None,
|
|
|
|
detailed_info = None, kind = None ):
|
2015-12-21 14:38:56 -05:00
|
|
|
return {
|
2016-02-28 23:04:12 -05:00
|
|
|
'extra_data': { 'required_namespace_import': namespace },
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
class PostComplete_test():
|
|
|
|
|
|
|
|
def setUp( self ):
|
|
|
|
self.ycm = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def tearDown( self ):
|
|
|
|
self.ycm.OnVimLeave()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def _SetupForCsharpCompletionDone( self, completions ):
|
|
|
|
with patch( 'ycm.vimsupport.InsertNamespace' ):
|
|
|
|
with patch( 'ycm.vimsupport.TextBeforeCursor',
|
|
|
|
return_value = ' Test' ):
|
|
|
|
request = MagicMock()
|
|
|
|
request.Done = MagicMock( return_value = True )
|
|
|
|
request.RawResponse = MagicMock( return_value = completions )
|
|
|
|
self.ycm._latest_completion_request = request
|
|
|
|
yield
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "cs" ] )
|
|
|
|
def GetCompleteDoneHooks_ResultOnCsharp_test( self, *args ):
|
|
|
|
result = self.ycm.GetCompleteDoneHooks()
|
|
|
|
eq_( 1, len( list( result ) ) )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
|
|
|
|
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( self, *args ):
|
|
|
|
result = self.ycm.GetCompleteDoneHooks()
|
|
|
|
eq_( 0, len( list( result ) ) )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
|
|
|
|
def OnCompleteDone_WithActionCallsIt_test( self, *args ):
|
|
|
|
action = MagicMock()
|
|
|
|
self.ycm._complete_done_hooks[ "txt" ] = action
|
|
|
|
self.ycm.OnCompleteDone()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
ok_( action.called )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ "txt" ] )
|
|
|
|
def OnCompleteDone_NoActionNoError_test( self, *args ):
|
|
|
|
self.ycm.OnCompleteDone()
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( self, *args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
result = self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( list( result ), completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'A' ) )
|
|
|
|
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( self,
|
|
|
|
*args ):
|
|
|
|
completions = [ BuildCompletion( "AAA" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Test' ) )
|
|
|
|
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( self,
|
|
|
|
*args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
result = self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( list( result ), completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( ' Quote' ) )
|
|
|
|
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( self,
|
|
|
|
*args ):
|
|
|
|
completions = [ BuildCompletion( "A" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
result = self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
assert_that( list( result ), empty() )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Test" )
|
|
|
|
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( self, *args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
result = self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( list( result ), completions )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
|
|
|
|
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( self,
|
|
|
|
*args ):
|
|
|
|
completions = [ BuildCompletion( "AAA" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
|
|
|
|
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( self,
|
|
|
|
*args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
result = self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( list( result ), completions )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
|
|
|
|
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( self,
|
|
|
|
*args ):
|
|
|
|
completions = [ BuildCompletion( "A" ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
result = self.ycm._FilterToMatchingCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
assert_that( list( result ), empty() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Te" )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( result, True )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "X" )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "AAA" ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = "Test" )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( result, False )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "A" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( result, False )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( "Te") )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( result, True )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( "X") )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = " Quote" )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "AAA" ) ]
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( "Test" ) )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "Test" ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( result, False )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( " Quote" ) )
|
|
|
|
@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' )
|
2016-03-06 12:13:43 -05:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( "A" ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
result = self.ycm._HasCompletionsThatCouldBeCompletedWithMoreText(
|
|
|
|
completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( result, False )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test( self ):
|
|
|
|
eq_( None, self.ycm._GetRequiredNamespaceImport( {} ) )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test( self ):
|
|
|
|
namespace = "A_NAMESPACE"
|
2015-09-09 11:08:41 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( namespace, self.ycm._GetRequiredNamespaceImport(
|
|
|
|
BuildCompletion( namespace )
|
|
|
|
) )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( self ):
|
|
|
|
with self._SetupForCsharpCompletionDone( [] ):
|
|
|
|
self.ycm._latest_completion_request.Done = MagicMock(
|
|
|
|
return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self ):
|
|
|
|
completions = [ BuildCompletion( None ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( 'Te' ) ):
|
|
|
|
eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( None ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
2016-04-06 18:12:50 -04:00
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
|
|
|
|
with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' ):
|
2016-02-28 23:04:12 -05:00
|
|
|
eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test(
|
|
|
|
self, *args ):
|
|
|
|
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
|
|
|
|
completions = [ BuildCompletion( *info ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
|
|
|
eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
|
|
|
|
completions = [ BuildCompletion( *info ),
|
|
|
|
BuildCompletion( insertion_text = "TestTest" ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
|
|
|
eq_( [ completions[ 0 ] ],
|
|
|
|
self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa
|
2016-02-28 23:04:12 -05:00
|
|
|
self ):
|
|
|
|
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
|
|
|
|
completions = [ BuildCompletion( insertion_text = info[ 0 ] ),
|
|
|
|
BuildCompletion( insertion_text = "TestTest" ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( *info[ 1: ] ) ):
|
|
|
|
eq_( [], self.ycm.GetCompletionsUserMayHaveCompleted() )
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test(
|
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( None ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ):
|
|
|
|
with patch( 'ycm.vimsupport.GetVariableValue',
|
|
|
|
GetVariableValue_CompleteItemIs( "Test" ) ):
|
|
|
|
eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test(
|
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( None ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
|
|
|
|
eq_( completions, self.ycm.GetCompletionsUserMayHaveCompleted() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2016-02-28 23:04:12 -05:00
|
|
|
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( self, *args ):
|
|
|
|
with self._SetupForCsharpCompletionDone( [] ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
|
|
|
|
self.ycm._OnCompleteDone_Csharp()
|
|
|
|
|
|
|
|
ok_( not vimsupport.InsertNamespace.called )
|
|
|
|
|
|
|
|
|
2016-03-06 12:13:43 -05:00
|
|
|
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test(
|
2016-02-28 23:04:12 -05:00
|
|
|
self, *args ):
|
|
|
|
completions = [ BuildCompletion( None ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
|
|
|
|
self.ycm._OnCompleteDone_Csharp()
|
|
|
|
|
|
|
|
ok_( not vimsupport.InsertNamespace.called )
|
|
|
|
|
|
|
|
|
|
|
|
def PostCompleteCsharp_ValueDoesInsertNamespace_test( self, *args ):
|
|
|
|
namespace = "A_NAMESPACE"
|
|
|
|
completions = [ BuildCompletion( namespace ) ]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
|
|
|
|
self.ycm._OnCompleteDone_Csharp()
|
|
|
|
|
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace )
|
|
|
|
|
|
|
|
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( self, *args ):
|
|
|
|
namespace = "A_NAMESPACE"
|
|
|
|
namespace2 = "ANOTHER_NAMESPACE"
|
|
|
|
completions = [
|
|
|
|
BuildCompletion( namespace ),
|
|
|
|
BuildCompletion( namespace2 ),
|
|
|
|
]
|
|
|
|
with self._SetupForCsharpCompletionDone( completions ):
|
|
|
|
with patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ):
|
|
|
|
with patch( 'ycm.vimsupport.PresentDialog', return_value = 1 ):
|
|
|
|
self.ycm._OnCompleteDone_Csharp()
|
|
|
|
|
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
|