def Subcommands_Format_WholeFile_Tabs_test( app ): filepath = PathToTestFile( 'test.js' ) RunTest( app, { 'description': 'Formatting is applied on the whole file ' 'with tabs composed of 2 spaces', 'request': { 'command': 'Format', 'filepath': filepath, 'options': { 'tab_size': 4, 'insert_spaces': False } }, 'expect': { 'response': requests.codes.ok, 'data': has_entries( { 'fixits': contains_exactly( has_entries( { 'chunks': contains_exactly( ChunkMatcher( '\t', LocationMatcher( filepath, 2, 1 ), LocationMatcher( filepath, 2, 3 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 3, 1 ), LocationMatcher( filepath, 3, 3 ) ), ChunkMatcher( ' ', LocationMatcher( filepath, 3, 14 ), LocationMatcher( filepath, 3, 14 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 4, 1 ), LocationMatcher( filepath, 4, 3 ) ), ChunkMatcher( ' ', LocationMatcher( filepath, 4, 14 ), LocationMatcher( filepath, 4, 14 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 5, 1 ), LocationMatcher( filepath, 5, 3 ) ), 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 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 24, 1 ), LocationMatcher( filepath, 24, 3 ) ), ChunkMatcher( '\t ', LocationMatcher( filepath, 25, 1 ), LocationMatcher( filepath, 25, 4 ) ), ChunkMatcher( '\t ', LocationMatcher( filepath, 26, 1 ), LocationMatcher( filepath, 26, 4 ) ), ChunkMatcher( '\t', LocationMatcher( filepath, 27, 1 ), LocationMatcher( filepath, 27, 3 ) ), ChunkMatcher( ' ', LocationMatcher( filepath, 27, 17 ), LocationMatcher( filepath, 27, 17 ) ), ) } ) ) } ) } } )
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 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_RefactorRename_MultipleFiles_test(app): RunTest( app, { 'description': 'RefactorRename works across files', 'request': { 'command': 'RefactorRename', 'arguments': ['this-is-a-longer-string'], 'line_num': 25, 'column_num': 9, 'filepath': PathToTestFile('test.ts'), }, 'expect': { 'response': requests.codes.ok, 'data': has_entries({ 'fixits': contains_exactly( has_entries({ 'chunks': contains_inanyorder( ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.ts'), 25, 7), LocationMatcher(PathToTestFile('test.ts'), 25, 10)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.ts'), 33, 15), LocationMatcher(PathToTestFile('test.ts'), 33, 18)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.ts'), 37, 1), LocationMatcher(PathToTestFile('test.ts'), 37, 4)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('file2.ts'), 1, 5), LocationMatcher(PathToTestFile('file2.ts'), 1, 8)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('file3.ts'), 1, 15), LocationMatcher(PathToTestFile('file3.ts'), 1, 18)), ChunkMatcher( 'this-is-a-longer-string', LocationMatcher(PathToTestFile('test.tsx'), 10, 8), LocationMatcher(PathToTestFile('test.tsx'), 10, 11)), ), 'location': LocationMatcher(PathToTestFile('test.ts'), 25, 9) })) }) } })