def GetCompletions_DirtyNamedBuffers_test(app): # This tests that when we have dirty buffers in our editor, tern actually # uses them correctly RunTest( app, { 'description': ('completion works for require object ' 'with query not prefix'), 'request': { 'filetype': 'javascript', 'filepath': PathToTestFile('requirejs_test.js'), 'line_num': 18, 'column_num': 11, 'file_data': { PathToTestFile('no_such_lib', 'no_such_file.js'): { 'contents': ('define( [], function() { return { big_endian_node: 1 } } )' ), 'filetypes': ['javascript'] } }, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completions': contains_inanyorder( CompletionEntryMatcher('big_endian_node', 'number'), CompletionEntryMatcher('toString', 'fn() -> string'), CompletionEntryMatcher('toLocaleString', 'fn() -> string'), CompletionEntryMatcher('valueOf', 'fn() -> number'), CompletionEntryMatcher('hasOwnProperty', 'fn(prop: string) -> bool'), CompletionEntryMatcher('isPrototypeOf', 'fn(obj: ?) -> bool'), CompletionEntryMatcher('propertyIsEnumerable', 'fn(prop: string) -> bool'), ), 'errors': empty(), }) }, })
def GetCompletions_SysPath_PythonSysPathInExtraConf_test( app ): RunTest( app, { 'description': 'Module is added to sys.path through the PythonSysPath ' 'function in extra conf file', 'request': { 'filetype' : 'python', 'filepath' : PathToTestFile( 'project', '__main__.py' ), 'line_num' : 3, 'column_num': 8 }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': has_item( CompletionEntryMatcher( 'SOME_CONSTANT', 'SOME_CONSTANT = 1' ) ), 'errors': empty() } ) } } )
def GenericLSPCompleter_GetCompletions_FilteredNoForce_test(app): request = BuildRequest(filepath=TEST_FILE, filetype='foo', line_num=1, column_num=3, contents='Java', event_name='FileReadyToParse') app.post_json('/event_notification', request) WaitUntilCompleterServerReady(app, 'foo') request.pop('event_name') response = app.post_json('/completions', BuildRequest(**request)) eq_(response.status_code, 200) print('Completer response: {}'.format(json.dumps(response.json, indent=2))) assert_that( response.json, has_entries({ 'completions': contains( CompletionEntryMatcher('JavaScript', 'JavaScript details'), ) }))
def GetCompletions_Unicode_InLine_test( app ): RunTest( app, { 'description': 'return completions for strings with multi-byte chars', 'request': { 'filetype' : 'python', 'filepath' : PathToTestFile( 'unicode.py' ), 'line_num' : 7, 'column_num': 14 }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains( CompletionEntryMatcher( 'center', 'def center(width: int, fillchar: str=...)' ) ), 'errors': empty() } ) } } )
def test_GenericLSPCompleter_GetCompletions_NotACompletionProvider( self, app): completer = handlers._server_state.GetFiletypeCompleter(['foo']) with patch.object(completer, '_is_completion_provider', False): request = BuildRequest(filepath=TEST_FILE, filetype='foo', line_num=1, column_num=3, contents='Java', event_name='FileReadyToParse') app.post_json('/event_notification', request) WaitUntilCompleterServerReady(app, 'foo') request.pop('event_name') response = app.post_json('/completions', BuildRequest(**request)) assert_that( response.json, has_entries({ 'completions': contains_exactly(CompletionEntryMatcher('Java', '[ID]')) }))
def GetCompletions_NumpyDoc_test( app ): RunTest( app, { 'description': 'Type hinting is working with docstrings ' 'in the Numpy format', 'request': { 'filetype' : 'python', 'filepath' : PathToTestFile( 'numpy_docstring.py' ), 'line_num' : 11, 'column_num': 18 }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains( CompletionEntryMatcher( 'SomeMethod', 'def SomeMethod()' ), ), 'errors': empty() } ) } } )
def GetCompletions_UnicodeInLineFilter_test( app ): RunTest( app, { 'description': 'member completion with a unicode identifier', 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'unicode.cc' ), 'line_num' : 9, 'column_num': 10, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 8, 'completions': contains_inanyorder( CompletionEntryMatcher( 'member_with_å_unicøde', 'int' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_QuotedInclude_AfterSpace_test( app ): RunTest( app, { 'description': 'completion of #include "dir with ', 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'test-include', 'main.cpp' ), 'line_num' : 9, 'column_num': 20, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 11, 'completions': contains_exactly( CompletionEntryMatcher( 'dir with spaces/' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_Fallback_Suggestions_test( app ): # TESTCASE1 (general_fallback/lang_c.c) RunTest( app, { 'description': '. after macro with some query text (.a_)', 'request': { 'filetype' : 'c', 'filepath' : PathToTestFile( 'general_fallback', 'lang_c.c' ), 'line_num' : 29, 'column_num': 23, 'force_semantic': False, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': has_item( CompletionEntryMatcher( 'a_parameter', '[ID]' ) ), 'errors': empty(), } ) }, } )
def GetCompletions_Require_Query_test( app ): RunTest( app, { 'description': 'semantic completion works for require object with query', 'request': { 'filetype' : 'javascript', 'filepath' : PathToTestFile( 'requirejs_test.js' ), 'line_num' : 3, 'column_num': 17, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains( CompletionEntryMatcher( 'mine_bitcoin', 'fn(how_much: ?) -> number' ), ), 'errors': empty(), } ) }, } )
def GetCompletions_cuda_test( app ): RunTest( app, { 'description': 'Completion of CUDA files', 'request': { 'filetype' : 'cuda', 'filepath' : PathToTestFile( 'cuda', 'completion_test.cu' ), 'line_num' : 16, 'column_num': 29, 'force_semantic': True, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 29, 'completions': contains( CompletionEntryMatcher( 'do_something', 'void' ), ), 'errors': empty(), } ) } } )
def GetCompletions_QuotedInclude_AfterDot_test( app ): RunTest( app, { 'description': 'completion of #include "quote/b.', 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'test-include', 'main.cpp' ), 'line_num' : 9, 'column_num': 28, 'compilation_flags': [ '-x', 'cpp' ] }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 27, 'completions': contains( CompletionEntryMatcher( 'd.hpp', '[File]' ) ), 'errors': empty(), } ) }, } )
def GetCompletions_QuotedInclude_AfterSpace_test( app ): RunTest( app, { 'description': 'completion of #include "dir with ', 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'test-include', 'main.cpp' ), 'line_num' : 11, 'column_num': 20, 'compilation_flags': [ '-x', 'cpp', '-nostdinc', '-nobuiltininc' ] }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 11, 'completions': contains( CompletionEntryMatcher( 'dir with spaces', '[Dir]' ) ), 'errors': empty(), } ) }, } )
def GetCompletions_NoForceAtTopLevel_NoImport_test( app ): RunTest( app, { 'description': 'When not forcing semantic completion, use no context', 'request': { 'filetype' : 'java', 'filepath' : ProjectPath( 'TestWidgetImpl.java' ), 'line_num' : 30, 'column_num': 20, 'force_semantic': False, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains( CompletionEntryMatcher( 'TestFactory', '[ID]', {} ), ), 'completion_start_column': 12, 'errors': empty(), } ) }, } )
def FilenameCompleter_Completion( app, contents, environ, filetype, completions ): completion_data = BuildRequest( contents = contents, filepath = PATH_TO_TEST_FILE, filetype = filetype, column_num = len( ToBytes( contents ) ) + 1 ) if completions: completion_matchers = [ CompletionEntryMatcher( *completion ) for completion in completions ] expected_results = contains_inanyorder( *completion_matchers ) else: expected_results = empty() with patch.dict( 'os.environ', environ ): results = app.post_json( '/completions', completion_data ).json[ 'completions' ] assert_that( results, expected_results )
def GetCompletions_ClangCLDriverExec_IncludeStatementCandidate_test( app ): RunTest( app, { 'description': 'Completion inside include statement with CL driver', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile( 'driver_mode_cl', 'executable', 'driver_mode_cl.cpp' ), 'line_num': 1, 'column_num': 34, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 11, 'completions': contains_inanyorder( CompletionEntryMatcher( 'driver_mode_cl_include.h\"' ), ), 'errors': empty(), } ) } } )
def GetCompletions_Package_test( app ): RunTest( app, { 'description': 'completion works for package statements', 'request': { 'filetype' : 'java', 'filepath' : ProjectPath( 'wobble', 'Wibble.java' ), 'line_num' : 1, 'column_num': 18, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 9, 'completions': contains( CompletionEntryMatcher( 'com.test.wobble', None, { 'kind': 'Module' } ), ), 'errors': empty(), } ) }, } )
def GetCompletions_PythonInterpreter_ExtraConfData_test( app ): filepath = PathToTestFile( 'project', '__main__.py' ) contents = ReadFile( filepath ) request = { 'filetype' : 'python', 'filepath' : filepath, 'contents' : contents, 'line_num' : 3, 'column_num': 8 } # Complete with a sys.path specified by the client that contains the path to a # third-party module. completion_request = CombineRequest( request, { 'extra_conf_data': { 'sys_path': [ PathToTestFile( 'project', 'third_party' ) ] } } ) assert_that( app.post_json( '/completions', completion_request ).json, has_entries( { 'completions': has_item( CompletionEntryMatcher( 'SOME_CONSTANT', 'SOME_CONSTANT = 1' ) ), 'errors': empty() } ) ) # Complete at the same position but no sys.path from the client. completion_request = CombineRequest( request, {} ) assert_that( app.post_json( '/completions', completion_request ).json, has_entries( { 'completions': empty(), 'errors': empty() } ) )
def GetCompletions_DefaultToIdentifier_test(app): filepath = PathToTestFile('testy', 'Program.cs') with WrapOmniSharpServer(app, filepath): contents = ReadFile(filepath) completion_data = BuildRequest(filepath=filepath, filetype='cs', contents=contents, line_num=10, column_num=7) response_data = app.post_json('/completions', completion_data).json print('Response: ', response_data) assert_that( response_data, has_entries({ 'completion_start_column': 4, 'completions': has_items(CompletionEntryMatcher('Console', '[ID]'), ), 'errors': empty(), }))
def GetCompletions_IdentifierCompleter_Unicode_InLine_test( app ): contents = """ This is some text cøntaining unicøde """ event_data = BuildRequest( contents = contents, filetype = 'css', event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) # query is 'tx' completion_data = BuildRequest( contents = 'tx ' + contents, filetype = 'css', column_num = 3 ) results = app.post_json( '/completions', completion_data ).json[ 'completions' ] assert_that( results, has_items( CompletionEntryMatcher( 'text', '[ID]' ) ) )
def GetCompletions_MoreThan100NoResolve_test( app ): RunTest( app, { 'description': 'We guess the right start codepoint without resolving', 'request': { 'filetype' : 'java', 'filepath' : ProjectPath( 'TestLauncher.java' ), 'line_num' : 4, 'column_num': 15, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': has_item( CompletionEntryMatcher( 'com.youcompleteme', None, { 'kind': 'Module' } ), ), 'completion_start_column': 8, 'errors': empty(), } ) }, } )
def GetCompletions_ClientDataGivenToExtraConf_Include_test( app ): app.post_json( '/load_extra_conf_file', { 'filepath': PathToTestFile( 'client_data', '.ycm_extra_conf.py' ) } ) filepath = PathToTestFile( 'client_data', 'include.cpp' ) completion_data = BuildRequest( filepath = filepath, filetype = 'cpp', contents = ReadFile( filepath ), line_num = 1, column_num = 11, extra_conf_data = { 'flags': [ '-x', 'c++' ] } ) results = app.post_json( '/completions', completion_data ).json[ 'completions' ] assert_that( results, has_item( CompletionEntryMatcher( 'include.hpp', extra_menu_info = '[File]' ) ) )
def GetCompletions_Unity_test( app ): RunTest( app, { 'description': 'Completion returns from file included in TU, but not in ' 'opened file', 'extra_conf': [ '.ycm_extra_conf.py' ], 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'unitya.cc' ), 'line_num' : 10, 'column_num': 24, 'force_semantic': True, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 20, 'completions': contains( CompletionEntryMatcher( 'this_is_an_it', 'int' ), ), 'errors': empty(), } ) } } )
def GetCompletions_Import_Class_test( app ): RunTest( app, { 'description': 'completion works for import statements with a single class', 'request': { 'filetype' : 'java', 'filepath' : ProjectPath( 'TestLauncher.java' ), 'line_num' : 4, 'column_num': 34, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 34, 'completions': contains( CompletionEntryMatcher( 'Tset;', None, { 'menu_text': 'Tset - com.youcompleteme.testing', 'kind': 'Class', } ) ), 'errors': empty(), } ) }, } )
def GetCompletions_WithFixIt_test( app ): filepath = ProjectPath( 'TestFactory.java' ) RunTest( app, { 'description': 'semantic completion with when additional textEdit', 'request': { 'filetype' : 'java', 'filepath' : filepath, 'line_num' : 19, 'column_num': 25, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 22, 'completions': contains_inanyorder( CompletionEntryMatcher( 'CUTHBERT', 'com.test.wobble.Wibble', { 'kind': 'EnumMember', 'extra_data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains( ChunkMatcher( 'Wibble', LocationMatcher( filepath, 19, 15 ), LocationMatcher( filepath, 19, 21 ) ), # OK, so it inserts the import ChunkMatcher( '\n\nimport com.test.wobble.Wibble;\n\n', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 3, 1 ) ), ), } ) ), } ), } ), ), 'errors': empty(), } ) }, } )
def GetCompletions_ProcMacro_test(app): StartRustCompleterServerInDirectory(app, PathToTestFile('macro')) filepath = PathToTestFile('macro', 'src', 'main.rs') contents = ReadFile(filepath) completion_data = BuildRequest(filepath=filepath, filetype='rust', contents=contents, line_num=33, column_num=14) results = [] expiration = time.time() + 60 while time.time() < expiration: results = app.post_json('/completions', completion_data).json['completions'] if len(results) > 0: break time.sleep(0.25) assert_that(results, has_item(CompletionEntryMatcher('checkpoint'))) # This completer does not require or support resolve assert_that(results[0], is_not(has_key('resolve'))) assert_that(results[0], is_not(has_key('item'))) # So (erroneously) resolving an item returns the item completion_data['resolve'] = 0 response = app.post_json('/resolve_completion', completion_data).json print(f"Resolve resolve: { pformat( response ) }") # We can't actually check the result because we don't know what completion # resolve ID 0 actually is (could be anything), so we just check that we get 1 # result, and that there are no errors. assert_that(response['completion'], is_not(None)) assert_that(response['errors'], empty())
def GetCompletions_QuotedInclude_QuoteIncludeFlag_test(app): RunTest( app, { 'description': 'completion of #include " with a -iquote flag', 'request': { 'filetype': 'cpp', 'filepath': PathToTestFile('test-include', 'main.cpp'), 'line_num': 9, 'column_num': 11, 'compilation_flags': [ '-x', 'cpp', '-iquote', PathToTestFile('test-include', 'quote') ] }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 11, 'completions': contains( CompletionEntryMatcher('.ycm_extra_conf.py', '[File]'), CompletionEntryMatcher('a.hpp', '[File]'), CompletionEntryMatcher('b.hpp', '[File]'), CompletionEntryMatcher('dir with spaces', '[Dir]'), CompletionEntryMatcher('main.cpp', '[File]'), CompletionEntryMatcher('quote', '[Dir]'), CompletionEntryMatcher('system', '[Dir]')), 'errors': empty(), }) }, })
def GetCompletions_RejectMultiLineInsertion_test(app): filepath = ProjectPath('TestLauncher.java') RunTest( app, { 'description': 'completion item discarded when not valid', 'request': { 'filetype': 'java', 'filepath': filepath, 'line_num': 28, 'column_num': 16, 'force_semantic': True }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'completion_start_column': 16, 'completions': contains_exactly( CompletionEntryMatcher( 'TestLauncher', 'com.test.TestLauncher.TestLauncher(int test)', {'kind': 'Constructor'}) # Note: There would be a suggestion here for the _real_ thing we want, # which is a TestLauncher.Launchable, but this would generate the code # for an anonymous inner class via a completion TextEdit (not # AdditionalTextEdit) which we don't support. ), 'errors': empty(), }) }, })
def GetCompletions_BracketInclude_FrameworkHeader_test( app ): RunTest( app, { 'description': 'completion of #include <OpenGL/', 'request': { 'filetype' : 'cpp', 'filepath' : PathToTestFile( 'test-include', 'main.cpp' ), 'line_num' : 15, 'column_num': 18, 'compilation_flags': [ '-x', 'cpp', '-nostdinc', '-nobuiltininc', '-iframework', PathToTestFile( 'test-include', 'Frameworks' ) ] }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completion_start_column': 18, 'completions': contains( CompletionEntryMatcher( 'gl.h', '[File]' ) ), 'errors': empty() } ) }, } )
def test_GetCompletions_IgnoreIdentifiers( self, app ): RunTest( app, { 'description': 'Identifier "test" is not returned as a suggestion', 'request': { 'line_num': 5, 'column_num': 6, 'filepath': PathToTestFile( 'identifier', 'test.js' ), }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': contains_exactly( CompletionEntryMatcher( 'foo', '(property) foo: string', extra_params = { 'kind': 'property', 'detailed_info': '(property) foo: string' } ) ) } ) } } )