def FixIt_Check_cpp11_Note(results): assert_that( results, has_entries({ 'fixits': contains( # First note: put parens around it has_entries({ 'text': contains_string('parentheses around the assignment'), 'chunks': contains( ChunkMatcher('(', LineColMatcher(59, 8), LineColMatcher(59, 8)), ChunkMatcher(')', LineColMatcher(61, 12), LineColMatcher(61, 12))), 'location': LineColMatcher(60, 1), }), # Second note: change to == has_entries({ 'text': contains_string('=='), 'chunks': contains( ChunkMatcher('==', LineColMatcher(60, 8), LineColMatcher(60, 9))), 'location': LineColMatcher(60, 1), })) }))
def test_Subcommands_Format_WholeFile( self, app ): filepath = PathToTestFile( 'goto.go' ) RunTest( app, { 'description': 'Formatting is applied on the whole file', 'request': { 'command': 'Format', 'filepath': filepath, 'options': { 'tab_size': 2, 'insert_spaces': True } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( ChunkMatcher( '', LocationMatcher( filepath, 8, 1 ), LocationMatcher( filepath, 8, 5 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 8, 5 ), LocationMatcher( filepath, 8, 5 ) ), ChunkMatcher( '', LocationMatcher( filepath, 12, 1 ), LocationMatcher( filepath, 12, 5 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 12, 5 ), LocationMatcher( filepath, 12, 5 ) ), ) } ) ) } ) } } )
def Subcommands_OrganizeImports_test( app ): filepath = PathToTestFile( 'imports.ts' ) RunTest( app, { 'description': 'OrganizeImports removes unused imports, ' 'coalesces imports from the same module, and sorts them', 'request': { 'command': 'OrganizeImports', 'filepath': filepath, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains( ChunkMatcher( matches_regexp( 'import \\* as lib from "library";\r?\n' 'import func, { func1, func2 } from "library";\r?\n' ), LocationMatcher( filepath, 1, 1 ), LocationMatcher( filepath, 2, 1 ) ), ChunkMatcher( '', LocationMatcher( filepath, 5, 1 ), LocationMatcher( filepath, 6, 1 ) ), ChunkMatcher( '', LocationMatcher( filepath, 9, 1 ), LocationMatcher( filepath, 10, 1 ) ), ) } ) ) } ) } } )
def Subcommands_RefactorRename_Simple_test( app ): RunTest( app, { 'description': 'RefactorRename works on a class name', 'request': { 'command': 'RefactorRename', 'arguments': [ 'test' ], 'line_num': 2, 'column_num': 8, 'filepath': PathToTestFile( 'test.ts' ), }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains_inanyorder( ChunkMatcher( 'test', LocationMatcher( PathToTestFile( 'test.ts' ), 14, 15 ), LocationMatcher( PathToTestFile( 'test.ts' ), 14, 18 ) ), ChunkMatcher( 'test', LocationMatcher( PathToTestFile( 'test.ts' ), 2, 7 ), LocationMatcher( PathToTestFile( 'test.ts' ), 2, 10 ) ), ), 'location': LocationMatcher( PathToTestFile( 'test.ts' ), 2, 8 ) } ) ) } ) } } )
def Subcommands_RefactorRename_Works_test( app ): main_filepath = PathToTestFile( 'common', 'src', 'main.rs' ) test_filepath = PathToTestFile( 'common', 'src', 'test.rs' ) RunTest( app, { 'description': 'RefactorRename on a function renames all its occurences', 'request': { 'command': 'RefactorRename', 'arguments': [ 'update_universe' ], 'line_num': 12, 'column_num': 16, 'filepath': main_filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_exactly( has_entries( { 'text': '', 'chunks': contains_exactly( ChunkMatcher( 'update_universe', LocationMatcher( test_filepath, 2, 8 ), LocationMatcher( test_filepath, 2, 23 ) ), ChunkMatcher( 'update_universe', LocationMatcher( main_filepath, 12, 5 ), LocationMatcher( main_filepath, 12, 20 ) ), ) } ) ) } ) } } )
def FixIt_Check_cpp11_Note( results ): assert_that( results, has_entries( { 'fixits': contains_exactly( # First note: put parens around it has_entries( { 'text': contains_string( 'parentheses around the assignment' ), 'chunks': contains_exactly( ChunkMatcher( '(', LineColMatcher( 59, 8 ), LineColMatcher( 59, 8 ) ), ChunkMatcher( ')', LineColMatcher( 61, 12 ), LineColMatcher( 61, 12 ) ) ), 'location': LineColMatcher( 60, 1 ), } ), # Second note: change to == has_entries( { 'text': contains_string( '==' ), 'chunks': contains_exactly( ChunkMatcher( '==', LineColMatcher( 60, 8 ), LineColMatcher( 60, 9 ) ) ), 'location': LineColMatcher( 60, 1 ), } ), # Unresolved, requires /resolve_fixit request has_entries( { 'text': 'Extract subexpression to variable', 'resolve': True, 'command': has_entries( { 'command': 'clangd.applyTweak' } ) } ) ) } ) )
def Subcommands_Format_WholeFile_test( app ): project_dir = PathToTestFile( 'common' ) StartRustCompleterServerInDirectory( app, project_dir ) filepath = os.path.join( project_dir, 'src', 'main.rs' ) RunTest( app, { 'description': 'Formatting is applied on the whole file', 'request': { 'command': 'Format', 'filepath': filepath, 'options': { 'tab_size': 2, 'insert_spaces': True } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains( ChunkMatcher( ' create_universe();\n' ' let builder = Builder {};\n' ' builder.build_\n', LocationMatcher( filepath, 12, 1 ), LocationMatcher( filepath, 15, 1 ) ), ChunkMatcher( 'fn format_test() {\n' ' let a: i32 = 5;\n', LocationMatcher( filepath, 17, 1 ), LocationMatcher( filepath, 22, 1 ) ), ) } ) ) } ) } } )
def Subcommands_Format_ExtraConf_BraceOnNewLine_test(app): WaitUntilCompleterServerReady(app, 'javascript') filepath = PathToTestFile('extra_confs', 'func.js') RunTest( app, { 'description': 'Format with an extra conf, braces on new line', 'request': { 'command': 'Format', 'filepath': filepath, 'options': { 'tab_size': 4, 'insert_spaces': True } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_exactly( ChunkMatcher(matches_regexp('\r?\n'), LocationMatcher(filepath, 1, 19), LocationMatcher(filepath, 1, 20)), ChunkMatcher(' ', LocationMatcher(filepath, 2, 1), LocationMatcher(filepath, 2, 1)), ) })) }) } })
def Subcommands_FixIt_Simple_test(): filepath = PathToTestFile( 'goto.go' ) fixit = has_entries( { 'fixits': contains( has_entries( { 'text': "Organize Imports", 'chunks': contains( ChunkMatcher( '', LocationMatcher( filepath, 8, 1 ), LocationMatcher( filepath, 9, 1 ) ), ChunkMatcher( '\tdummy() //GoTo\n', LocationMatcher( filepath, 9, 1 ), LocationMatcher( filepath, 9, 1 ) ), ChunkMatcher( '', LocationMatcher( filepath, 12, 1 ), LocationMatcher( filepath, 13, 1 ) ), ChunkMatcher( '\tdiagnostics_test\n', LocationMatcher( filepath, 13, 1 ), LocationMatcher( filepath, 13, 1 ) ), ), } ), ) } ) yield ( RunFixItTest, 'Only one fixit returned', filepath, 1, 1, fixit )
def test_Subcommands_OrganizeImports(self, app): filepath = PathToTestFile('testy', 'ImportTest.cs') with WrapOmniSharpServer(app, filepath): request = BuildRequest(command_arguments=['OrganizeImports'], line_num=11, column_num=2, contents=ReadFile(filepath), filetype='cs', filepath=filepath) response = app.post_json('/run_completer_command', request).json print('completer response = ', response) assert_that( response, has_entries({ 'fixits': contains_exactly( has_entries({ 'location': LocationMatcher(filepath, 11, 2), 'chunks': contains_exactly( ChunkMatcher( ' ', LocationMatcher(filepath, 5, 1), LocationMatcher(filepath, 5, 2), ), ChunkMatcher( '', LocationMatcher(filepath, 1, 1), LocationMatcher(filepath, 3, 1), )) })) }))
def Subcommands_RefactorRename_MultipleFiles_test( app ): AbstractTestWidget = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'test', 'AbstractTestWidget.java' ) TestFactory = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'test', 'TestFactory.java' ) TestLauncher = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'test', 'TestLauncher.java' ) TestWidgetImpl = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'test', 'TestWidgetImpl.java' ) RunTest( app, { 'description': 'RefactorRename works across files', 'request': { 'command': 'RefactorRename', 'arguments': [ 'a-quite-long-string' ], 'filepath': TestLauncher, 'line_num': 32, 'column_num': 13, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries ( { 'fixits': contains( has_entries( { 'chunks': contains( ChunkMatcher( 'a-quite-long-string', LocationMatcher( AbstractTestWidget, 10, 15 ), LocationMatcher( AbstractTestWidget, 10, 39 ) ), ChunkMatcher( 'a-quite-long-string', LocationMatcher( TestFactory, 28, 9 ), LocationMatcher( TestFactory, 28, 33 ) ), ChunkMatcher( 'a-quite-long-string', LocationMatcher( TestLauncher, 32, 11 ), LocationMatcher( TestLauncher, 32, 35 ) ), ChunkMatcher( 'a-quite-long-string', LocationMatcher( TestWidgetImpl, 20, 15 ), LocationMatcher( TestWidgetImpl, 20, 39 ) ), ), 'location': LocationMatcher( TestLauncher, 32, 13 ) } ) ) } ) } } )
def Subcommands_RefactorRename_MultipleFiles_test(app): RunTest( app, { 'description': 'RefactorRename works across files', 'request': { 'command': 'RefactorRename', 'arguments': ['this-is-a-longer-string'], 'line_num': 22, 'column_num': 8, 'filepath': PathToTestFile('test.js'), }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains( has_entries({ 'chunks': contains_inanyorder( ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.js'), 22, 7), LocationMatcher(PathToTestFile('test.js'), 22, 10)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.js'), 30, 15), LocationMatcher(PathToTestFile('test.js'), 30, 18)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.js'), 34, 1), LocationMatcher(PathToTestFile('test.js'), 34, 4)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('file2.js'), 1, 5), LocationMatcher(PathToTestFile('file2.js'), 1, 8)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('file3.js'), 1, 15), LocationMatcher(PathToTestFile('file3.js'), 1, 18)), ), 'location': LocationMatcher(PathToTestFile('test.js'), 22, 8) })) }) } })
def test_GetCompletions_WithFixIt(self, 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.CUTHBERT : Wibble', { 'kind': 'EnumMember', 'extra_data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_exactly( 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 test_Subcommands_Format_Range_Spaces(self, app): filepath = PathToTestFile('test.js') RunTest( app, { 'description': 'Formatting is applied on some part of the file ' 'with tabs composed of 4 spaces by default', 'request': { 'command': 'Format', 'filepath': filepath, 'range': { 'start': { 'line_num': 5, 'column_num': 3, }, 'end': { 'line_num': 8, 'column_num': 6 } }, 'options': { 'tab_size': 4, 'insert_spaces': True } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_exactly( ChunkMatcher( ' ', LocationMatcher( filepath, 5, 1), LocationMatcher(filepath, 5, 3)), ChunkMatcher( ' ', LocationMatcher(filepath, 6, 1), LocationMatcher(filepath, 6, 5)), ChunkMatcher( ' ', LocationMatcher(filepath, 7, 1), LocationMatcher(filepath, 7, 5)), ChunkMatcher( ' ', LocationMatcher( filepath, 8, 1), LocationMatcher(filepath, 8, 3)), ) })) }) } })
def Subcommands_RefactorRename_MultipleFiles_test( app ): filepath = PathToTestFile( 'test.ts' ) file2 = PathToTestFile( 'file2.ts' ) file3 = PathToTestFile( 'file3.ts' ) contents = ReadFile( filepath ) event_data = BuildRequest( filepath = filepath, filetype = 'typescript', contents = contents, event_name = 'BufferVisit' ) app.post_json( '/event_notification', event_data ) request = BuildRequest( completer_target = 'filetype_default', command_arguments = [ 'RefactorRename', 'this-is-a-longer-string' ], line_num = 25, column_num = 9, contents = contents, filetype = 'typescript', filepath = filepath ) response = app.post_json( '/run_completer_command', request ).json pprint.pprint( response, indent = 2 ) assert_that( response, has_entries ( { 'fixits': contains( has_entries( { 'chunks': contains_inanyorder( ChunkMatcher( 'this-is-a-longer-string', LocationMatcher( filepath, 25, 7 ), LocationMatcher( filepath, 25, 10 ) ), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher( filepath, 33, 15 ), LocationMatcher( filepath, 33, 18 ) ), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher( filepath, 37, 1 ), LocationMatcher( filepath, 37, 4 ) ), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher( file2, 1, 5 ), LocationMatcher( file2, 1, 8 ) ), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher( file3, 1, 15 ), LocationMatcher( file3, 1, 18 ) ), ), 'location': LocationMatcher( filepath, 25, 9 ) } ) ) } ) )
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': 'Field', 'extra_data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains( # For some reason, jdtls feels it's OK to replace the text # before the cursor. Perhaps it does this to canonicalise the # path ? ChunkMatcher( 'Wibble', LocationMatcher( filepath, 19, 15 ), LocationMatcher( filepath, 19, 21 ) ), # When doing an import, eclipse likes to add two newlines # after the package. I suppose this is config in real eclipse, # but there's no mechanism to configure this in jdtl afaik. ChunkMatcher( '\n\n', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 1, 18 ) ), # OK, so it inserts the import ChunkMatcher( 'import com.test.wobble.Wibble;', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 1, 18 ) ), # More newlines. Who doesn't like newlines?! ChunkMatcher( '\n\n', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 1, 18 ) ), # For reasons known only to the eclipse JDT developers, it # seems to want to delete the lines after the package first. ChunkMatcher( '', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 3, 1 ) ), ), } ) ), } ), } ), ), 'errors': empty(), } ) }, } )
def Subcommands_FixIt_test( app ): RunTest( app, { 'description': 'FixIt works on a non-existing method', 'request': { 'command': 'FixIt', 'line_num': 35, 'column_num': 12, 'filepath': PathToTestFile( 'test.ts' ), }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_inanyorder( has_entries( { 'text': "Declare method 'nonExistingMethod'", 'chunks': contains_exactly( ChunkMatcher( matches_regexp( '^\r?\n' ' nonExistingMethod\\(\\) {\r?\n' ' throw new Error\\("Method not implemented."\\);\r?\n' ' }$', ), LocationMatcher( PathToTestFile( 'test.ts' ), 25, 12 ), LocationMatcher( PathToTestFile( 'test.ts' ), 25, 12 ) ) ), 'location': LocationMatcher( PathToTestFile( 'test.ts' ), 35, 12 ) } ), has_entries( { 'text': "Declare property 'nonExistingMethod'", 'chunks': contains_exactly( ChunkMatcher( matches_regexp( '^\r?\n' ' nonExistingMethod: any;$' ), LocationMatcher( PathToTestFile( 'test.ts' ), 25, 12 ), LocationMatcher( PathToTestFile( 'test.ts' ), 25, 12 ) ) ), 'location': LocationMatcher( PathToTestFile( 'test.ts' ), 35, 12 ) } ), has_entries( { 'text': "Add index signature for property 'nonExistingMethod'", 'chunks': contains_exactly( ChunkMatcher( matches_regexp( '^\r?\n' ' \\[x: string\\]: any;$' ), LocationMatcher( PathToTestFile( 'test.ts' ), 25, 12 ), LocationMatcher( PathToTestFile( 'test.ts' ), 25, 12 ) ) ), 'location': LocationMatcher( PathToTestFile( 'test.ts' ), 35, 12 ) } ) ) } ) } } )
def Subcommands_FixIt_InvalidURI_test( app ): filepath = PathToTestFile( 'simple_eclipse_project', 'src', 'com', 'test', 'TestFactory.java' ) fixits = has_entries ( { 'fixits': contains( has_entries( { 'text': "Change type of 'test' to 'boolean'", 'chunks': contains( # For some reason, eclipse returns modifies as deletes + adds, # although overlapping ranges aren't allowed. ChunkMatcher( 'boolean', LocationMatcher( '', 14, 12 ), LocationMatcher( '', 14, 12 ) ), ChunkMatcher( '', LocationMatcher( '', 14, 12 ), LocationMatcher( '', 14, 15 ) ), ), } ), ) } ) contents = ReadFile( filepath ) # Wait for jdt.ls to have parsed the file and returned some diagnostics for tries in range( 0, 60 ): results = app.post_json( '/event_notification', BuildRequest( filepath = filepath, filetype = 'java', contents = contents, event_name = 'FileReadyToParse' ) ) if results.json: break time.sleep( .25 ) with patch( 'ycmd.completers.language_server.language_server_protocol.UriToFilePath', side_effect = lsp.InvalidUriException ): RunTest( app, { 'description': 'Invalid URIs do not make us crash', 'request': { 'command': 'FixIt', 'line_num': 27, 'column_num': 12, 'filepath': filepath, }, 'expect': { 'response': requests.codes.ok, 'data': fixits, } } )
def Subcommands_RefactorRename_SimpleUnicode_test(app): RunTest( app, { 'description': 'RefactorRename works with Unicode characters', 'request': { 'command': 'RefactorRename', 'arguments': ['ø'], 'line_num': 14, 'column_num': 3, 'filepath': PathToTestFile('unicode.ts'), }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_inanyorder( ChunkMatcher( 'ø', LocationMatcher( PathToTestFile('unicode.ts'), 14, 3), LocationMatcher( PathToTestFile('unicode.ts'), 14, 5)), ChunkMatcher( 'ø', LocationMatcher( PathToTestFile('unicode.ts'), 20, 27), LocationMatcher( PathToTestFile('unicode.ts'), 20, 29)), ChunkMatcher( 'ø', LocationMatcher( PathToTestFile('unicode.ts'), 23, 5), LocationMatcher( PathToTestFile('unicode.ts'), 23, 7)), ChunkMatcher( 'ø', LocationMatcher( PathToTestFile('unicode.ts'), 27, 17), LocationMatcher( PathToTestFile('unicode.ts'), 27, 19)), ), 'location': LocationMatcher(PathToTestFile('unicode.ts'), 14, 3) })) }) } })
def Subcommands_Format_Range_Tabs_test(app): filepath = PathToTestFile('test.js') RunTest( app, { 'description': 'Formatting is applied on some part of the file ' 'with tabs instead of spaces', 'request': { 'command': 'Format', 'filepath': filepath, 'range': { 'start': { 'line_num': 6, 'column_num': 3, }, 'end': { 'line_num': 11, 'column_num': 6 } }, 'options': { 'tab_size': 4, 'insert_spaces': False } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains( has_entries({ 'chunks': contains( ChunkMatcher('\t\t', LocationMatcher(filepath, 6, 1), LocationMatcher(filepath, 6, 5)), ChunkMatcher('\t\t', LocationMatcher(filepath, 7, 1), LocationMatcher(filepath, 7, 5)), ChunkMatcher('\t', LocationMatcher(filepath, 8, 1), LocationMatcher(filepath, 8, 3)), ChunkMatcher(' ', LocationMatcher(filepath, 8, 6), LocationMatcher(filepath, 8, 6)), ) })) }) } })
def FixIt_Check_SubexprExtract_Resolved( results ): assert_that( results, has_entries( { 'fixits': contains_exactly( has_entries( { 'text': 'Extract subexpression to variable', 'chunks': contains_exactly( ChunkMatcher( 'auto dummy = i + 3;\n ', LineColMatcher( 84, 3 ), LineColMatcher( 84, 3 ) ), ChunkMatcher( 'dummy', LineColMatcher( 84, 14 ), LineColMatcher( 84, 21 ) ), ) } ) ) } ) )
def Subcommands_Format_WholeFile_test(app): # RLS can't execute textDocument/formatting if any file # under the project root has errors, so we need to use # a different project just for formatting. # For further details check https://github.com/go-lang/rls/issues/1397 project_dir = PathToTestFile() StartGoCompleterServerInDirectory(app, project_dir) filepath = os.path.join(project_dir, 'goto.go') RunTest( app, { 'description': 'Formatting is applied on the whole file', 'request': { 'command': 'Format', 'filepath': filepath, 'options': { 'tab_size': 2, 'insert_spaces': True } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_exactly( ChunkMatcher('', LocationMatcher( filepath, 8, 1), LocationMatcher(filepath, 9, 1)), ChunkMatcher('\tdummy() //GoTo\n', LocationMatcher(filepath, 9, 1), LocationMatcher(filepath, 9, 1)), ChunkMatcher('', LocationMatcher(filepath, 12, 1), LocationMatcher(filepath, 13, 1)), ChunkMatcher('\tdiagnostics_test\n', LocationMatcher(filepath, 13, 1), LocationMatcher(filepath, 13, 1)), ) })) }) } })
def Subcommands_Format_WholeFile_test( app ): filepath = PathToTestFile( 'common', 'src', 'main.rs' ) RunTest( app, { 'description': 'Formatting is applied on the whole file', 'request': { 'command': 'Format', 'filepath': filepath, 'options': { 'tab_size': 2, 'insert_spaces': True } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( # Let's just rewrite the whole file... ChunkMatcher( "mod test;\n\nuse test::*;\n\nstruct Earth {}" "\nstruct Mars {}\ntrait Atmosphere {}\nimpl " "Atmosphere for Earth {}\nimpl Atmosphere for " "Mars {}\n\nfn main() {\n create_universe();" "\n let builder = Builder {};\n builder." "build_\n}\n\nfn format_test() {\n let a: " "i32 = 5;\n}\n", LocationMatcher( filepath, 1, 1 ), LocationMatcher( filepath, 23, 1 ) ), ) } ) ) } ) } } )
def test_Subcommands_FixIt_Basic(self, app): filepath = PathToTestFile('common', 'src', 'main.rs') RunTest( app, { 'description': 'Simple FixIt test', 'request': { 'command': 'FixIt', 'line_num': 17, 'column_num': 2, 'filepath': filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_exactly( ChunkMatcher( 'pub(crate) ', LocationMatcher(filepath, 17, 1), LocationMatcher(filepath, 17, 1))) })) }) }, })
def Subcommands_FixIt_test( app ): filepath = PathToTestFile( 'test.js' ) RunTest( app, { 'description': 'FixIt works on a non-existing method', 'request': { 'command': 'FixIt', 'line_num': 32, 'column_num': 19, 'filepath': filepath, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_inanyorder( has_entries( { 'text': "Declare method 'nonExistingMethod'", 'chunks': contains( ChunkMatcher( matches_regexp( '^\r?\n' ' nonExistingMethod\\(\\) {\r?\n' ' throw new Error\\("Method not implemented."\\);\r?\n' ' }$', ), LocationMatcher( filepath, 22, 12 ), LocationMatcher( filepath, 22, 12 ) ) ), 'location': LocationMatcher( filepath, 32, 19 ) } ) ) } ) } } )
def GetCompletions_ForceAtTopLevel_WithImport_test( app ): filepath = ProjectPath( 'TestWidgetImpl.java' ) RunTest( app, { 'description': 'Top level completions have import FixIts', 'request': { 'filetype' : 'java', 'filepath' : filepath, 'line_num' : 34, 'column_num': 16, 'force_semantic': True, }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'completions': has_item( CompletionEntryMatcher( 'InputStreamReader', None, { 'kind': 'Class', 'menu_text': 'InputStreamReader - java.io', 'extra_data': has_entries( { 'fixits': contains( has_entries( { 'chunks': contains( ChunkMatcher( '\n\nimport java.io.InputStreamReader;\n\n', LocationMatcher( filepath, 1, 18 ), LocationMatcher( filepath, 3, 1 ) ), ), } ) ), } ), } ), ), 'completion_start_column': 12, 'errors': empty(), } ) }, } )
def Subcommands_FixIt_ApplySuggestion_test(app): # Similarly to textDocument/formatting, if a file has errors # RLS won't respond with `rls.applySuggestions` command. project_dir = PathToTestFile('formatting') StartRustCompleterServerInDirectory(app, project_dir) filepath = os.path.join(project_dir, 'src', 'main.rs') RunTest( app, { 'description': 'Simple FixIt test', 'request': { 'command': 'FixIt', 'line_num': 8, 'column_num': 13, 'filepath': filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains( has_entries({ 'chunks': contains( ChunkMatcher('_x', LocationMatcher(filepath, 8, 13), LocationMatcher(filepath, 8, 14))) })) }) } })
def Subcommands_FixIt_Unity_test( app ): file_path = PathToTestFile( 'unitya.cc' ) args = { 'filetype' : 'cpp', 'completer_target' : 'filetype_default', 'contents' : ReadFile( file_path ), 'filepath' : file_path, 'command_arguments': [ 'FixIt' ], 'line_num' : 11, 'column_num' : 17, } app.post_json( '/load_extra_conf_file', { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ), } ) # Get the diagnostics for the file. event_data = BuildRequest( **args ) results = app.post_json( '/run_completer_command', event_data ).json pprint( results ) assert_that( results, has_entries( { 'fixits': contains( has_entries( { 'text': contains_string( "expected ';' after expression" ), 'chunks': contains( ChunkMatcher( ';', LocationMatcher( file_path, 11, 18 ), LocationMatcher( file_path, 11, 18 ) ), ), 'location': LocationMatcher( file_path, 11, 18 ), } ) ) } ) )
def Subcommands_FixIt_DeglobImport_test(app): project_dir = PathToTestFile('common') StartRustCompleterServerInDirectory(app, project_dir) filepath = os.path.join(project_dir, 'src', 'main.rs') RunTest( app, { 'description': 'Simple FixIt test', 'request': { 'command': 'FixIt', 'line_num': 3, 'column_num': 1, 'filepath': filepath }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains( has_entries({ 'chunks': contains( ChunkMatcher('{create_universe, Builder}', LocationMatcher(filepath, 3, 11), LocationMatcher(filepath, 3, 12))) })) }) } })
def Subcommands_RefactorRename_SimpleUnicode_test( app ): filepath = PathToTestFile( 'unicode.ts' ) contents = ReadFile( filepath ) event_data = BuildRequest( filepath = filepath, filetype = 'typescript', contents = contents, event_name = 'BufferVisit' ) app.post_json( '/event_notification', event_data ) request = BuildRequest( completer_target = 'filetype_default', command_arguments = [ 'RefactorRename', 'ø' ], line_num = 14, column_num = 3, contents = contents, filetype = 'typescript', filepath = filepath ) response = app.post_json( '/run_completer_command', request ).json pprint.pprint( response, indent = 2 ) assert_that( response, has_entries ( { 'fixits': contains( has_entries( { 'chunks': contains_inanyorder( ChunkMatcher( 'ø', LocationMatcher( filepath, 14, 3 ), LocationMatcher( filepath, 14, 5 ) ), ChunkMatcher( 'ø', LocationMatcher( filepath, 20, 27 ), LocationMatcher( filepath, 20, 29 ) ), ChunkMatcher( 'ø', LocationMatcher( filepath, 23, 5 ), LocationMatcher( filepath, 23, 7 ) ), ChunkMatcher( 'ø', LocationMatcher( filepath, 27, 17), LocationMatcher( filepath, 27, 19 ) ), ), 'location': LocationMatcher( filepath, 14, 3 ) } ) ) } ) )