Add omnifunc tests

This commit is contained in:
micbou 2017-07-07 14:11:45 +02:00
parent 600383fbac
commit 139e3fbaf9
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
2 changed files with 48 additions and 3 deletions

View File

@ -24,6 +24,7 @@ from builtins import * # noqa
import vim import vim
from ycm import vimsupport from ycm import vimsupport
from ycmd import utils
from ycmd.completers.completer import Completer from ycmd.completers.completer import Completer
from ycm.client.base_request import BaseRequest, HandleServerException from ycm.client.base_request import BaseRequest, HandleServerException
@ -47,7 +48,7 @@ class OmniCompleter( Completer ):
def ShouldUseNow( self, request_data ): def ShouldUseNow( self, request_data ):
self._omnifunc = vimsupport.VimExpressionToPythonType( '&omnifunc' ) self._omnifunc = utils.ToUnicode( vim.eval( '&omnifunc' ) )
if not self._omnifunc: if not self._omnifunc:
return False return False
if self.ShouldUseCache(): if self.ShouldUseCache():

View File

@ -610,8 +610,6 @@ def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test(
omnifunc = Omnifunc ) omnifunc = Omnifunc )
with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 5 ) ): with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 5 ) ):
# Make sure there is an omnifunc set up.
ycm.OnFileReadyToParse()
ycm.SendCompletionRequest() ycm.SendCompletionRequest()
assert_that( assert_that(
vimsupport.CurrentLineAndColumn(), vimsupport.CurrentLineAndColumn(),
@ -624,3 +622,49 @@ def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test(
'completion_start_column': 6 'completion_start_column': 6
} ) } )
) )
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_NoSemanticTrigger_test( ycm ):
def Omnifunc( findstart, base ):
if findstart:
return 0
return [ 'test' ]
current_buffer = VimBuffer( 'buffer',
contents = [ 'te' ],
filetype = 'java',
omnifunc = Omnifunc )
with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 3 ) ):
ycm.SendCompletionRequest()
assert_that(
ycm.GetCompletionResponse(),
has_entries( {
'completions': empty(),
'completion_start_column': 1
} )
)
@YouCompleteMeInstance( { 'cache_omnifunc': 0 } )
def OmniCompleter_GetCompletions_NoCache_ForceSemantic_test( ycm ):
def Omnifunc( findstart, base ):
if findstart:
return 0
return [ 'test' ]
current_buffer = VimBuffer( 'buffer',
contents = [ 'te' ],
filetype = 'java',
omnifunc = Omnifunc )
with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 3 ) ):
ycm.SendCompletionRequest( force_semantic = True )
assert_that(
ycm.GetCompletionResponse(),
has_entries( {
'completions': ToBytesOnPY2( [ 'test' ] ),
'completion_start_column': 1
} )
)