2015-08-28 10:26:18 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
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/>.
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
from mock import ( MagicMock, DEFAULT )
|
2015-08-28 10:26:18 -04:00
|
|
|
from nose.tools import eq_
|
|
|
|
from hamcrest import assert_that, empty
|
|
|
|
from ycm import vimsupport
|
|
|
|
from ycm.youcompleteme import YouCompleteMe
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def GetCompleteDoneHooks_ResultOnCsharp_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.CurrentFiletypes = MagicMock( return_value = [ "cs" ] )
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-08-31 12:51:23 -04:00
|
|
|
result = ycm_state.GetCompleteDoneHooks()
|
|
|
|
eq_( 1, len( list( result ) ) )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.CurrentFiletypes = MagicMock( return_value = [ "txt" ] )
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-08-31 12:51:23 -04:00
|
|
|
result = ycm_state.GetCompleteDoneHooks()
|
|
|
|
eq_( 0, len( list( result ) ) )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def OnCompleteDone_WithActionCallsIt_test():
|
|
|
|
vimsupport.CurrentFiletypes = MagicMock( return_value = [ "txt" ] )
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-08-31 12:51:23 -04:00
|
|
|
action = MagicMock()
|
|
|
|
ycm_state._complete_done_hooks[ "txt" ] = action
|
|
|
|
ycm_state.OnCompleteDone()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
assert action.called
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def OnCompleteDone_NoActionNoError_test():
|
|
|
|
vimsupport.CurrentFiletypes = MagicMock( return_value = [ "txt" ] )
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state.OnCompleteDone()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def FilterToCompletedCompletions_NewVim_MatchIsReturned_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Test" )
|
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
|
|
|
result = ycm_state.FilterToCompletedCompletions( completions, False )
|
|
|
|
|
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
|
|
|
def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "A" )
|
|
|
|
completions = [ _BuildCompletion( "AAA" ) ]
|
|
|
|
|
|
|
|
ycm_state.FilterToCompletedCompletions( completions, False )
|
|
|
|
|
|
|
|
|
|
|
|
def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Test" )
|
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
|
|
|
result = ycm_state.FilterToCompletedCompletions( completions, False )
|
|
|
|
|
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
|
|
|
def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( " Quote" )
|
|
|
|
completions = [ _BuildCompletion( "A" ) ]
|
|
|
|
|
|
|
|
result = ycm_state.FilterToCompletedCompletions( completions, False )
|
|
|
|
|
|
|
|
assert_that( list( result ), empty() )
|
|
|
|
|
|
|
|
|
|
|
|
def FilterToCompletedCompletions_OldVim_MatchIsReturned_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Test" )
|
2015-08-31 12:51:23 -04:00
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
result = ycm_state.FilterToCompletedCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = "X" )
|
2015-08-31 12:51:23 -04:00
|
|
|
completions = [ _BuildCompletion( "AAA" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
ycm_state.FilterToCompletedCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = "Test" )
|
2015-08-31 12:51:23 -04:00
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
result = ycm_state.FilterToCompletedCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
eq_( list( result ), completions )
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Quote" )
|
|
|
|
completions = [ _BuildCompletion( "A" ) ]
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
result = ycm_state.FilterToCompletedCompletions( completions, False )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
assert_that( list( result ), empty() )
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Te" )
|
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
result = ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
eq_( result, True )
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = "X" )
|
|
|
|
completions = [ _BuildCompletion( "AAA" ) ]
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = "Test" )
|
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
result = ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
eq_( result, False )
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Quote" )
|
|
|
|
completions = [ _BuildCompletion( "A" ) ]
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
result = ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
|
|
|
|
|
|
|
eq_( result, False )
|
|
|
|
|
|
|
|
|
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Te" )
|
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
|
|
|
result = ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
|
|
|
|
|
|
|
eq_( result, True )
|
|
|
|
|
|
|
|
|
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "X" )
|
|
|
|
completions = [ _BuildCompletion( "AAA" ) ]
|
|
|
|
|
|
|
|
ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
|
|
|
|
|
|
|
|
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Test" )
|
|
|
|
completions = [ _BuildCompletion( "Test" ) ]
|
|
|
|
|
|
|
|
result = ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
|
|
|
|
|
|
|
eq_( result, False )
|
|
|
|
|
|
|
|
|
|
|
|
def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( " Quote" )
|
|
|
|
completions = [ _BuildCompletion( "A" ) ]
|
|
|
|
|
|
|
|
result = ycm_state.HasCompletionsThatCouldBeCompletedWithMoreText( completions )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
eq_( result, False )
|
|
|
|
|
|
|
|
|
|
|
|
def GetRequiredNamespaceImport_ReturnNoneForNoExtraData_test():
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
|
|
|
|
eq_( None, ycm_state.GetRequiredNamespaceImport( {} ) )
|
|
|
|
|
|
|
|
|
|
|
|
def GetRequiredNamespaceImport_ReturnNamespaceFromExtraData_test():
|
|
|
|
namespace = "A_NAMESPACE"
|
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
|
|
|
|
eq_( namespace, ycm_state.GetRequiredNamespaceImport(
|
|
|
|
_BuildCompletion( namespace )
|
|
|
|
))
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def GetCompletedCompletions_ReturnEmptyIfNotDone_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = _SetupForCsharpCompletionDone( [] )
|
|
|
|
ycm_state._latest_completion_request.Done = MagicMock( return_value = False )
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
eq_( [], ycm_state.GetCompletedCompletions() )
|
|
|
|
|
|
|
|
|
|
|
|
def GetCompletedCompletions_ReturnEmptyIfPendingMatches_NewVim_test():
|
|
|
|
completions = [ _BuildCompletion( None ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Te" )
|
|
|
|
|
|
|
|
eq_( [], ycm_state.GetCompletedCompletions() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
|
|
|
|
def GetCompletedCompletions_ReturnEmptyIfPendingMatches_OldVim_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
completions = [ _BuildCompletion( None ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Te" )
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
eq_( [], ycm_state.GetCompletedCompletions() )
|
|
|
|
|
|
|
|
|
|
|
|
def GetCompletedCompletions_ReturnMatchIfExactMatches_NewVim_test():
|
|
|
|
info = [ "NS","Test", "Abbr", "Menu", "Info", "Kind" ]
|
|
|
|
completions = [ _BuildCompletion( *info ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( *info[ 1 : ] )
|
|
|
|
|
|
|
|
eq_( completions, ycm_state.GetCompletedCompletions() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def GetCompletedCompletions_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test():
|
|
|
|
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
|
|
|
|
completions = [ _BuildCompletion( *info ),
|
|
|
|
_BuildCompletion( insertion_text = "TestTest" ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( *info[ 1 : ] )
|
|
|
|
|
|
|
|
eq_( [ completions[ 0 ] ], ycm_state.GetCompletedCompletions() )
|
|
|
|
|
|
|
|
|
|
|
|
def GetCompletedCompletions_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test():
|
|
|
|
info = [ "NS", "Test", "Abbr", "Menu", "Info", "Kind" ]
|
|
|
|
completions = [ _BuildCompletion( insertion_text = info[ 0 ] ),
|
|
|
|
_BuildCompletion( insertion_text = "TestTest" ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( *info[ 1 : ] )
|
|
|
|
|
|
|
|
eq_( [], ycm_state.GetCompletedCompletions() )
|
|
|
|
|
|
|
|
|
|
|
|
def GetCompletedCompletions_ReturnMatchIfMatches_NewVim_test():
|
2015-08-31 12:51:23 -04:00
|
|
|
completions = [ _BuildCompletion( None ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
2015-09-09 11:08:41 -04:00
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = True )
|
|
|
|
vimsupport.GetVariableValue = GetVariableValue_CompleteItemIs( "Test" )
|
|
|
|
|
|
|
|
eq_( completions, ycm_state.GetCompletedCompletions() )
|
|
|
|
|
|
|
|
|
|
|
|
def GetCompletedCompletions_ReturnMatchIfMatches_OldVim_test():
|
|
|
|
completions = [ _BuildCompletion( None ) ]
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
|
|
|
vimsupport.VimVersionAtLeast = MagicMock( return_value = False )
|
2015-08-31 12:51:23 -04:00
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Test" )
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
eq_( completions, ycm_state.GetCompletedCompletions() )
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
def PostCompleteCsharp_EmptyDoesntInsertNamespace_test():
|
|
|
|
ycm_state = _SetupForCsharpCompletionDone( [] )
|
|
|
|
|
|
|
|
ycm_state.OnCompleteDone_Csharp()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
assert not vimsupport.InsertNamespace.called
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
|
|
|
|
def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
completions = [ _BuildCompletion( None ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state.OnCompleteDone_Csharp()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
assert not vimsupport.InsertNamespace.called
|
|
|
|
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def PostCompleteCsharp_ValueDoesInsertNamespace_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
namespace = "A_NAMESPACE"
|
|
|
|
completions = [ _BuildCompletion( namespace ) ]
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
2015-08-28 10:26:18 -04:00
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state.OnCompleteDone_Csharp()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace )
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test():
|
2015-08-28 10:26:18 -04:00
|
|
|
namespace = "A_NAMESPACE"
|
|
|
|
namespace2 = "ANOTHER_NAMESPACE"
|
|
|
|
completions = [
|
|
|
|
_BuildCompletion( namespace ),
|
|
|
|
_BuildCompletion( namespace2 ),
|
|
|
|
]
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state = _SetupForCsharpCompletionDone( completions )
|
2015-08-28 10:26:18 -04:00
|
|
|
vimsupport.PresentDialog = MagicMock( return_value = 1 )
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
ycm_state.OnCompleteDone_Csharp()
|
2015-08-28 10:26:18 -04:00
|
|
|
|
|
|
|
vimsupport.InsertNamespace.assert_called_once_with( namespace2 )
|
|
|
|
|
|
|
|
|
2015-08-31 12:51:23 -04:00
|
|
|
def _SetupForCsharpCompletionDone( completions ):
|
2015-08-28 10:26:18 -04:00
|
|
|
ycm_state = YouCompleteMe( MagicMock( spec_set = dict ) )
|
|
|
|
request = MagicMock();
|
|
|
|
request.Done = MagicMock( return_value = True )
|
|
|
|
request.RawResponse = MagicMock( return_value = completions )
|
|
|
|
ycm_state._latest_completion_request = request
|
|
|
|
vimsupport.InsertNamespace = MagicMock()
|
|
|
|
vimsupport.TextBeforeCursor = MagicMock( return_value = " Test" )
|
|
|
|
return ycm_state
|
|
|
|
|
|
|
|
|
2015-09-09 11:08:41 -04:00
|
|
|
def _BuildCompletion( namespace = None, insertion_text = 'Test',
|
|
|
|
menu_text = None, extra_menu_info = None,
|
|
|
|
detailed_info = None, kind = None ):
|
2015-08-28 10:26:18 -04:00
|
|
|
return {
|
|
|
|
'extra_data': { 'required_namespace_import' : namespace },
|
2015-09-09 11:08:41 -04:00
|
|
|
'insertion_text': insertion_text,
|
|
|
|
'menu_text': menu_text,
|
|
|
|
'extra_menu_info': extra_menu_info,
|
|
|
|
'kind': kind,
|
|
|
|
'detailed_info': detailed_info,
|
2015-08-28 10:26:18 -04:00
|
|
|
}
|
2015-09-09 11:08:41 -04: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,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
return DEFAULT
|
|
|
|
return MagicMock( side_effect = Result )
|