From 417045e8c192a529e4ed4e5b6119cc8d6dcf67cd Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Sun, 30 Aug 2020 23:56:55 +0200 Subject: [PATCH] test: Add a test for issue 40 --- tests/issues.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++ tests/support/mod.rs | 16 ++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/issues.rs diff --git a/tests/issues.rs b/tests/issues.rs new file mode 100644 index 00000000..2eaff818 --- /dev/null +++ b/tests/issues.rs @@ -0,0 +1,50 @@ +mod support; + +use tokio::io::{AsyncBufRead, AsyncWrite}; + +use lsp_types::{ + DocumentSymbolParams, DocumentSymbolResponse, PublishDiagnosticsParams, TextDocumentIdentifier, +}; + +async fn document_symbols( + stdin: &mut (dyn AsyncWrite + std::marker::Unpin + Send), + stdout: &mut (dyn AsyncBufRead + std::marker::Unpin + Send), + id: u64, + uri: &str, +) -> DocumentSymbolResponse { + support::run_method_call::( + stdin, + stdout, + id, + DocumentSymbolParams { + text_document: TextDocumentIdentifier { + uri: support::test_url(uri), + }, + work_done_progress_params: Default::default(), + partial_result_params: Default::default(), + }, + ) + .await + .unwrap() +} + +#[test] +fn issue_40() { + support::send_rpc(|stdin, stdout| { + Box::pin(async move { + let text = r#" +type U = (Int, Int) + +() +"#; + support::did_open(stdin, "test.glu", text).await; + + let diagnostic: PublishDiagnosticsParams = + support::expect_notification(&mut *stdout).await; + + assert_eq!(diagnostic.uri, support::test_url("test.glu")); + + document_symbols(stdin, stdout, 1, "test.glu").await; + }) + }); +} diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 8f78c77a..a20c6885 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -55,6 +55,22 @@ where .await } +pub async fn run_method_call( + writer: &mut (dyn AsyncWrite + std::marker::Unpin + Send), + reader: &mut (dyn AsyncBufRead + std::marker::Unpin + Send), + id: u64, + value: T::Params, +) -> T::Result +where + T: lsp_types::request::Request, +{ + let call = method_call(T::METHOD, id, value); + + write_message(writer, call).await.unwrap(); + + expect_response(reader).await +} + pub fn method_call(method: &str, id: u64, value: T) -> Call where T: Serialize,