From 139e3fbaf9861ec50c780c818a60e6001445ba48 Mon Sep 17 00:00:00 2001 From: micbou Date: Fri, 7 Jul 2017 14:11:45 +0200 Subject: [PATCH] Add omnifunc tests --- python/ycm/omni_completer.py | 3 +- python/ycm/tests/omni_completer_test.py | 48 +++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/python/ycm/omni_completer.py b/python/ycm/omni_completer.py index b4cc7268..25ec3459 100644 --- a/python/ycm/omni_completer.py +++ b/python/ycm/omni_completer.py @@ -24,6 +24,7 @@ from builtins import * # noqa import vim from ycm import vimsupport +from ycmd import utils from ycmd.completers.completer import Completer from ycm.client.base_request import BaseRequest, HandleServerException @@ -47,7 +48,7 @@ class OmniCompleter( Completer ): def ShouldUseNow( self, request_data ): - self._omnifunc = vimsupport.VimExpressionToPythonType( '&omnifunc' ) + self._omnifunc = utils.ToUnicode( vim.eval( '&omnifunc' ) ) if not self._omnifunc: return False if self.ShouldUseCache(): diff --git a/python/ycm/tests/omni_completer_test.py b/python/ycm/tests/omni_completer_test.py index aeb96091..0bc1e2a9 100644 --- a/python/ycm/tests/omni_completer_test.py +++ b/python/ycm/tests/omni_completer_test.py @@ -610,8 +610,6 @@ def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test( omnifunc = Omnifunc ) with MockVimBuffers( [ current_buffer ], current_buffer, ( 3, 5 ) ): - # Make sure there is an omnifunc set up. - ycm.OnFileReadyToParse() ycm.SendCompletionRequest() assert_that( vimsupport.CurrentLineAndColumn(), @@ -624,3 +622,49 @@ def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test( '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 + } ) + )