def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ): current_buffer = VimBuffer( 'buffer', filetype = 'c', number = 5, window = 2 ) test_utils.VIM_MATCHES = [ VimMatch( 'YcmWarningSection', '\%3l\%5c\_.\{-}\%3l\%7c' ), VimMatch( 'YcmWarningSection', '\%3l\%3c\_.\{-}\%3l\%9c' ), VimMatch( 'YcmErrorSection', '\%3l\%8c' ) ] with MockVimBuffers( [ current_buffer ], current_buffer ): ycm.UpdateMatches() assert_that( test_utils.VIM_MATCHES, empty() )
def YouCompleteMe_ShowDiagnostics_NoDiagnosticsDetected_test( ycm, set_location_list, post_vim_message, *args ): current_buffer = VimBuffer( 'buffer', filetype = 'cpp' ) with MockVimBuffers( [ current_buffer ], current_buffer ): with patch( 'ycm.client.event_notification.EventNotification.Response', return_value = {} ): ycm.ShowDiagnostics() post_vim_message.assert_has_exact_calls( [ call( 'Forcing compilation, this will block Vim until done.', warning = False ), call( 'Diagnostics refreshed', warning = False ), call( 'No warnings or errors detected.', warning = False ) ] ) set_location_list.assert_called_once_with( [] )
def YouCompleteMe_ToggleLogs_WithoutParameters_test(ycm, post_vim_message): # We test on a Python buffer because the Python completer has subserver # logfiles. python_buffer = VimBuffer('buffer.py', filetype='python') with MockVimBuffers([python_buffer], python_buffer): ycm.ToggleLogs() assert_that( # Argument passed to PostVimMessage. post_vim_message.call_args[0][0], matches_regexp('Available logfiles are:\n' 'jedihttp_\d+_stderr_.+.log\n' 'jedihttp_\d+_stdout_.+.log\n' 'ycm_.+.log\n' 'ycmd_\d+_stderr_.+.log\n' 'ycmd_\d+_stdout_.+.log'))
def YouCompleteMe_DebugInfo_ServerNotRunning_test( ycm ): StopServer( ycm ) current_buffer = VimBuffer( 'current_buffer' ) with MockVimBuffers( [ current_buffer ], current_buffer ): assert_that( ycm.DebugInfo(), matches_regexp( 'Client logfile: .+\n' 'Server errored, no debug info from server\n' 'Server running at: .+\n' 'Server process ID: \d+\n' 'Server logfiles:\n' ' .+\n' ' .+' ) )
def test_ResolveCompletionItem_NoUserData(self, ycm, post_vim_message): def CompletionResponse(*args): return { 'completions': [{ 'insertion_text': 'insertion_text', 'menu_text': 'menu_text', 'extra_menu_info': 'extra_menu_info', 'detailed_info': 'detailed_info', 'kind': 'kind' }], 'completion_start_column': 3, 'errors': [] } current_buffer = VimBuffer('buffer') with MockVimBuffers([current_buffer], [current_buffer]): with MockCompletionRequest(CompletionResponse): ycm.SendCompletionRequest() assert_that(ycm.CompletionRequestReady()) response = ycm.GetCompletionResponse() post_vim_message.assert_not_called() assert_that( response, has_entries({ 'completions': contains_exactly( has_entries({ 'word': 'insertion_text', 'abbr': 'menu_text', 'menu': 'extra_menu_info', 'info': 'detailed_info', 'kind': 'k', 'dup': 1, 'empty': 1 })), 'completion_start_column': 3 })) item = response['completions'][0] item.pop('user_data') with MockResolveRequest(ServerError('must not be called')): assert_that(ycm.ResolveCompletionItem(item), equal_to(False)) post_vim_message.assert_not_called()
def OmniCompleter_GetCompletions_Cache_ObjectListObject_Unicode_test(ycm): def Omnifunc(findstart, base): if findstart: return 12 return { 'words': [{ 'word': 'ålpha∫et', 'abbr': 'å∫∫®', 'menu': 'µ´~¨á', 'info': '^~fo', 'kind': '˚' }, { 'word': 'π†´ß†π', 'abbr': 'ÅııÂʉÍÊ', 'menu': '˜‰ˆËʉÍÊ', 'info': 'ȈÏØʉÍÊ', 'kind': 'Ê' }, { 'word': 'test', 'abbr': 'ÅııÂʉÍÊ', 'menu': '˜‰ˆËʉÍÊ', 'info': 'ȈÏØʉÍÊ', 'kind': 'Ê' }] } current_buffer = VimBuffer('buffer', contents=['†åsty_π.t'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], current_buffer, (1, 13)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': contains({ 'word': 'test', 'abbr': 'ÅııÂʉÍÊ', 'menu': '˜‰ˆËʉÍÊ', 'info': 'ȈÏØʉÍÊ', 'kind': 'Ê' }), 'completion_start_column': 13 }))
def OmniCompleter_GetCompletions_NoCache_ObjectList_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return [{ 'word': 'a', 'abbr': 'ABBR', 'menu': 'MENU', 'info': 'INFO', 'kind': 'K' }, { 'word': 'test', 'abbr': 'ABBRTEST', 'menu': 'MENUTEST', 'info': 'INFOTEST', 'kind': 'T' }] current_buffer = VimBuffer('buffer', contents=['test.tt'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 7)): ycm.SendCompletionRequest() # We don't filter the result - we expect the omnifunc to do that # based on the query we supplied (Note: that means no fuzzy matching!). assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ToBytesOnPY2([{ 'word': 'a', 'abbr': 'ABBR', 'menu': 'MENU', 'info': 'INFO', 'kind': 'K' }, { 'word': 'test', 'abbr': 'ABBRTEST', 'menu': 'MENUTEST', 'info': 'INFOTEST', 'kind': 'T' }]), 'completion_start_column': 6 }))
def SendCompletionRequest_ErrorFromServer_test(ycm, post_vim_message, logger): current_buffer = VimBuffer('buffer') with MockVimBuffers([current_buffer], [current_buffer]): with MockCompletionRequest(ServerError('Server error')): ycm.SendCompletionRequest() ok_(ycm.CompletionRequestReady()) response = ycm.GetCompletionResponse() logger.exception.assert_called_with('Error while handling server ' 'response') post_vim_message.assert_has_exact_calls( [call('Server error', truncate=True)]) assert_that( response, has_entries({ 'completions': empty(), 'completion_start_column': -1 }))
def SendCommandRequest_IgnoreFileTypeOption_test(ycm, *args): current_buffer = VimBuffer('buffer') with MockVimBuffers([current_buffer], [current_buffer]): expected_args = (['GoTo'], '', { 'options': { 'tab_size': 2, 'insert_spaces': True }, }) with patch('ycm.youcompleteme.SendCommandRequest') as send_request: ycm.SendCommandRequest(['ft=ycm:ident', 'GoTo'], '', False, 1, 1) send_request.assert_called_once_with(*expected_args) with patch('ycm.youcompleteme.SendCommandRequest') as send_request: ycm.SendCommandRequest(['GoTo', 'ft=python'], '', False, 1, 1) send_request.assert_called_once_with(*expected_args)
def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ): current_buffer = VimBuffer( 'buffer', filetype = 'c', number = 5 ) test_utils.VIM_MATCHES_FOR_WINDOW.clear() test_utils.VIM_MATCHES_FOR_WINDOW[ 1 ] = [ VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ), VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' ), VimMatch( 'YcmErrorSection', '\\%3l\\%8c' ) ] with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): ycm.UpdateMatches() assert_that( test_utils.VIM_MATCHES_FOR_WINDOW, has_entries( { 1: empty() } ) )
def test_SendCommandRequest_ExtraConfData_UndefinedValue(self, ycm): current_buffer = VimBuffer('buffer') with MockVimBuffers([current_buffer], [current_buffer]): with patch('ycm.youcompleteme.SendCommandRequest') as send_request: ycm.SendCommandRequest(['GoTo'], 'belowright', False, 1, 1) assert_that( # Positional arguments passed to SendCommandRequest. send_request.call_args[0], contains_exactly( contains_exactly('GoTo'), 'belowright', 'same-buffer', has_entries({ 'options': has_entries({ 'tab_size': 2, 'insert_spaces': True, }) })))
def YouCompleteMe_DebugInfo_ServerRunning_test(ycm): current_buffer = VimBuffer('current_buffer') with MockVimBuffers([current_buffer], current_buffer): assert_that( ycm.DebugInfo(), matches_regexp( 'Client logfile: .+\n' 'Server Python interpreter: .+\n' 'Server Python version: .+\n' 'Server has Clang support compiled in: (True|False)\n' 'Clang version: .+\n' 'No extra configuration file found\n' 'Server running at: .+\n' 'Server process ID: \d+\n' 'Server logfiles:\n' ' .+\n' ' .+'))
def YouCompleteMe_ToggleLogs_WithoutParameters_SelectLogfileNotAlreadyOpen_test( ycm, open_filename, *args): current_buffer = VimBuffer('current_buffer') with MockVimBuffers([current_buffer], current_buffer): ycm.ToggleLogs() open_filename.assert_has_exact_calls([ call( ycm._server_stderr, { 'size': 12, 'watch': True, 'fix': True, 'focus': False, 'position': 'end' }) ])
def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test( ycm ): current_buffer_file = os.path.realpath( 'current_βuffer' ) current_buffer = VimBuffer( name = current_buffer_file, number = 1, contents = [ 'current_buffer_contents' ], filetype = 'some_filetype', modified = True ) deleted_buffer_file = os.path.realpath( 'deleted_βuffer' ) deleted_buffer = VimBuffer( name = deleted_buffer_file, number = 2, contents = [ 'deleted_buffer_contents' ], filetype = 'some_filetype', modified = False ) with patch( 'ycm.client.event_notification.EventNotification.' 'PostDataToHandlerAsync' ) as post_data_to_handler_async: with MockVimBuffers( [ current_buffer, deleted_buffer ], [ current_buffer ] ): ycm.OnBufferUnload( deleted_buffer.number ) assert_that( # Positional arguments passed to PostDataToHandlerAsync. post_data_to_handler_async.call_args[ 0 ], contains_exactly( has_entries( { 'filepath': deleted_buffer_file, 'line_num': 1, 'column_num': 1, 'file_data': has_entries( { current_buffer_file: has_entries( { 'contents': 'current_buffer_contents\n', 'filetypes': [ 'some_filetype' ] } ), deleted_buffer_file: has_entries( { 'contents': 'deleted_buffer_contents\n', 'filetypes': [ 'some_filetype' ] } ) } ), 'event_name': 'BufferUnload' } ), 'event_notification' ) )
def SendCompletionRequest_UnicodeWorkingDirectory_test(ycm): unicode_dir = PathToTestFile('uni¢𐍈d€') current_buffer = VimBuffer(PathToTestFile('uni¢𐍈d€', 'current_buffer')) def ServerResponse(*args): return {'completions': [], 'completion_start_column': 1} with CurrentWorkingDirectory(unicode_dir): with MockVimBuffers([current_buffer], [current_buffer]): with MockCompletionRequest(ServerResponse): ycm.SendCompletionRequest() ok_(ycm.CompletionRequestReady()) assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': empty(), 'completion_start_column': 1 }))
def OmniCompleter_GetCompletions_Cache_ListFilter_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return ['a', 'b', 'cdef'] current_buffer = VimBuffer('buffer', contents=['test.t'], filetype='java', omnifunc=Omnifunc) with MockVimBuffers([current_buffer], current_buffer, (1, 6)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': empty(), 'completion_start_column': 6 }))
def OmniCompleter_GetCompletions_FiletypeDisabled_SemanticTrigger_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return ['a', 'b', 'cdef'] current_buffer = VimBuffer('buffer', contents=['test.'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 6)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': empty(), 'completion_start_column': 6 }))
def test_OmniCompleter_GetCompletions_NoCache_NoSemanticTrigger(self, ycm): def Omnifunc(findstart, base): if findstart: return 0 return ['test'] current_buffer = VimBuffer('buffer', contents=['te'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 3)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': empty(), 'completion_start_column': 1 }))
def OmniCompleter_GetCompletions_NoCache_ForceSemantic_test(ycm): def Omnifunc(findstart, base): if findstart: return 0 return ['test'] current_buffer = VimBuffer('buffer', contents=['te'], filetype=FILETYPE, 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 }))
def YouCompleteMe_ToggleLogs_WithParameters_test( ycm, open_filename, close_buffers_for_filename ): logfile_buffer = VimBuffer( ycm._client_logfile, window = 1 ) with MockVimBuffers( [ logfile_buffer ], logfile_buffer ): ycm.ToggleLogs( os.path.basename( ycm._client_logfile ), 'nonexisting_logfile', os.path.basename( ycm._server_stdout ) ) open_filename.assert_has_exact_calls( [ call( ycm._server_stdout, { 'size': 12, 'watch': True, 'fix': True, 'focus': False, 'position': 'end' } ) ] ) close_buffers_for_filename.assert_has_exact_calls( [ call( ycm._client_logfile ) ] )
def test_SendCommandRequest_ExtraConfVimData_Works(self, ycm): current_buffer = VimBuffer('buffer') with MockVimBuffers([current_buffer], [current_buffer]): with patch('ycm.youcompleteme.SendCommandRequest') as send_request: ycm.SendCommandRequest(['GoTo'], 'aboveleft', False, 1, 1) assert_that( # Positional arguments passed to SendCommandRequest. send_request.call_args[0], contains_exactly( contains_exactly('GoTo'), 'aboveleft', 'same-buffer', has_entries({ 'options': has_entries({ 'tab_size': 2, 'insert_spaces': True, }), 'extra_conf_data': has_entries({'tempname()': '_TEMP_FILE_'}), })))
def OmniCompleter_GetCompletions_Cache_Object_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return {'words': ['a', 'b', 'CDtEF']} current_buffer = VimBuffer('buffer', contents=['test.t'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 6)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ['CDtEF'], 'completion_start_column': 6 }))
def OmniCompleter_GetCompletions_NoCache_List_Filter_Unicode_test(ycm): def Omnifunc(findstart, base): if findstart: return 12 return ['πππππππ yummy πie'] current_buffer = VimBuffer('buffer', contents=['†åsty_π.ππ'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 17)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ToBytesOnPY2(['πππππππ yummy πie']), 'completion_start_column': 13 }))
def OmniCompleter_GetCompletions_AllFiletypesDisabled_ForceSemantic_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return ['a', 'b', 'cdef'] current_buffer = VimBuffer('buffer', contents=['test.'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 6)): ycm.SendCompletionRequest(force_semantic=True) assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ToBytesOnPY2(['a', 'b', 'cdef']), 'completion_start_column': 6 }))
def OmniCompleter_GetCompletions_NoCache_List_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return ['a', 'b', 'cdef'] current_buffer = VimBuffer('buffer', contents=['test.'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 5)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ToBytesOnPY2(['a', 'b', 'cdef']), 'completion_start_column': 6 }))
def OmniCompleter_GetCompletions_Cache_ObjectListObject_test(ycm): def Omnifunc(findstart, base): if findstart: return 5 return { 'words': [{ 'word': 'a', 'abbr': 'ABBR', 'menu': 'MENU', 'info': 'INFO', 'kind': 'K' }, { 'word': 'test', 'abbr': 'ABBRTEST', 'menu': 'MENUTEST', 'info': 'INFOTEST', 'kind': 'T' }] } current_buffer = VimBuffer('buffer', contents=['test.tt'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 7)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ToBytesOnPY2([{ 'word': 'test', 'abbr': 'ABBRTEST', 'menu': 'MENUTEST', 'info': 'INFOTEST', 'kind': 'T', 'equal': 1 }]), 'completion_start_column': 6 }))
def test_ConvertDiagnosticToTextProperties( self ): for diag, contents, result in [ # Error in middle of the line [ SimpleDiagnosticToJson( 1, 16, 1, 23 ), [ 'Highlight this error please' ], YcmTextPropertyTupleMatcher( 1, 16, 1, 23 ) ], # Error at the end of the line [ SimpleDiagnosticToJson( 1, 16, 1, 21 ), [ 'Highlight this warning' ], YcmTextPropertyTupleMatcher( 1, 16, 1, 21 ) ], [ SimpleDiagnosticToJson( 1, 16, 1, 19 ), [ 'Highlight unicøde' ], YcmTextPropertyTupleMatcher( 1, 16, 1, 19 ) ], # Non-positive position [ SimpleDiagnosticToJson( 0, 0, 0, 0 ), [ 'Some contents' ], YcmTextPropertyTupleMatcher( 1, 1, 1, 1 ) ], [ SimpleDiagnosticToJson( -1, -2, -3, -4 ), [ 'Some contents' ], YcmTextPropertyTupleMatcher( 1, 1, 1, 1 ) ], ]: with self.subTest( diag = diag, contents = contents, result = result ): current_buffer = VimBuffer( 'foo', number = 1, contents = [ '' ] ) target_buffer = VimBuffer( 'bar', number = 2, contents = contents ) with MockVimBuffers( [ current_buffer, target_buffer ], [ current_buffer, target_buffer ] ): actual = diagnostic_interface._ConvertDiagnosticToTextProperties( target_buffer.number, diag ) print( actual ) assert_that( actual, result )
def StartColumnCompliance(ycm, omnifunc_start_column, ycm_completions, ycm_start_column): def Omnifunc(findstart, base): if findstart: return omnifunc_start_column return ['foo'] current_buffer = VimBuffer('buffer', contents=['fo'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 2)): ycm.SendCompletionRequest(force_semantic=True) assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ToBytesOnPY2(ycm_completions), 'completion_start_column': ycm_start_column }))
def OmniCompleter_GetCompletions_Cache_UseFindStart_test(ycm): def Omnifunc(findstart, base): if findstart: return 0 return ['a', 'b', 'cdef'] current_buffer = VimBuffer('buffer', contents=['test.t'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 6)): ycm.SendCompletionRequest() # There are no results because the query 'test.t' doesn't match any # candidate (and cache_omnifunc=1, so we FilterAndSortCandidates). assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': empty(), 'completion_start_column': 1 }))
def OmniCompleter_GetCompletions_Cache_List_Unicode_test(ycm): def Omnifunc(findstart, base): if findstart: return 12 return ['†est', 'å_unicode_identifier', 'πππππππ yummy πie'] current_buffer = VimBuffer('buffer', contents=['†åsty_π.'], filetype=FILETYPE, omnifunc=Omnifunc) with MockVimBuffers([current_buffer], [current_buffer], (1, 12)): ycm.SendCompletionRequest() assert_that( ycm.GetCompletionResponse(), has_entries({ 'completions': ['å_unicode_identifier', 'πππππππ yummy πie', '†est'], 'completion_start_column': 13 }))