def test_completions(): """An example test which does very little""" completion_list = server.completions( fake_server, CompletionParams(TextDocumentIdentifier('file://fake_doc.txt'), Position(0, 2), None)) # test the list is empty for now assert completion_list.items == []
def test_goto_definition_finds_line(): server.workspace.get_document = Mock(return_value=fake_document) params = TextDocumentPositionParams( TextDocumentIdentifier(fake_document_uri), Position(1, 21)) definition = jump_to_definition(server, params)[0] start = definition.range.start assert start.line == 350 and start.character == 6
def test_did_close(): _reset_mocks() params = DidCloseTextDocumentParams( TextDocumentIdentifier(fake_document_uri)) did_close(server, params) # Check if show message is called server.show_message.assert_called_once()
def test_hover(client_server, datadir): client, server = client_server _init(client, datadir) path = datadir / 'CMakeLists.txt' _open(client, path, 'project()') response = client.lsp.send_request( HOVER, TextDocumentPositionParams(TextDocumentIdentifier(path.as_uri()), Position())).result(timeout=CALL_TIMEOUT) assert '<PROJECT-NAME>' in response.contents.value
def test_document_symbol(self): items = self.client.lsp.send_request( DOCUMENT_SYMBOL, DocumentSymbolParams( TextDocumentIdentifier( (self.folder / 'class_example.sv').as_uri()))).result() names = [i.name for i in items] assert "tb" in names assert "Packet" in names
def test_completion(): fake_document_identifier = TextDocumentIdentifier(fake_document_uri) server.workspace.get_document = Mock(return_value=fake_document) params = CompletionParams( fake_document_identifier, Position(4, 13), CompletionContext(CompletionTriggerKind()), ) completions = complete_code(server, params) assert any(filter(lambda x: x.label == "__doc__", completions.items))
def test_formatting(client_server, datadir): client, server = client_server _init(client, datadir) path = datadir / "CMakeLists.txt" _open(client, path, "a ( b c ) ") response = client.lsp.send_request( FORMATTING, DocumentFormattingParams(TextDocumentIdentifier(path.as_uri()), FormattingOptions(2, True)), ).result(timeout=CALL_TIMEOUT) assert response[0].newText == "a(b c)\n"
def test_completions_triggercharacter_package(client_server, datadir): client, server = client_server _init(client, datadir) path = datadir / 'CMakeLists.txt' _open(client, path, 'find_package(') response = client.lsp.send_request( COMPLETION, CompletionParams( TextDocumentIdentifier(path.as_uri()), Position(0, 13), CompletionContext(CompletionTriggerKind.TriggerCharacter, '('))).result(timeout=CALL_TIMEOUT) assert 'Boost' in [x.label for x in response.items]
def _test_completion(client_server, datadir, content: str, context: Optional[CompletionContext]): client, server = client_server _init(client, datadir) path = datadir / "CMakeLists.txt" _open(client, path, content) params = CompletionParams(TextDocumentIdentifier(path.as_uri()), Position(0, len(content)), context) if context is None: # some clients do not send context del params.context return client.lsp.send_request(COMPLETION, params).result(timeout=CALL_TIMEOUT)
def test_completions_invoked(client_server, datadir): client, server = client_server _init(client, datadir) path = datadir / 'CMakeLists.txt' _open(client, path, 'projec') response = client.lsp.send_request( COMPLETION, CompletionParams(TextDocumentIdentifier(path.as_uri()), Position( 0, 6), CompletionContext( CompletionTriggerKind.Invoked))).result(timeout=CALL_TIMEOUT) item = next(filter(lambda x: x.label == 'project', response.items), None) assert item is not None assert '<PROJECT-NAME>' in item.documentation
def test_format_should_return_whole_file_text_edit(self): service = GalaxyToolFormatService() params = DocumentFormattingParams( TextDocumentIdentifier("test"), options=FormattingOptions(tab_size=4, insert_spaces=True), ) actual = service.format(FAKE_UNFORMATTED_DOCUMENT, params) assert len(actual) == 1 assert actual[0].range.start.line == 0 assert actual[0].range.start.character == 0 assert actual[0].range.end.line == 3 assert actual[0].range.end.character == 0
def test_hover(): server.workspace.get_document = Mock(return_value=fake_document) params = TextDocumentPositionParams( TextDocumentIdentifier(fake_document_uri), Position(1, 21)) hover = document_hover(server, params) assert 'A class whose instances are single test cases.' in hover.value
def test_goto_definition_finds_file(): server.workspace.get_document = Mock(return_value=fake_document) params = TextDocumentPositionParams( TextDocumentIdentifier(fake_document_uri), Position(1, 21)) definition = jump_to_definition(server, params)[0] assert uri_to_path(definition.uri).endswith('case.py')