From 1dfd06fc8aadd5d621112716fe0e59aed5dfc767 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 6 Dec 2018 21:07:31 +0100 Subject: Use json comparison code from cargo for heavy tests --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'crates/ra_lsp_server/tests/heavy_tests/main.rs') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index cbc0c8844..63d53fb01 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -1,5 +1,7 @@ mod support; +use serde_json::json; + use ra_lsp_server::req::{Runnables, RunnablesParams}; use crate::support::project; @@ -21,7 +23,7 @@ fn foo() { text_document: server.doc_id("lib.rs"), position: None, }, - r#"[ + json!([ { "args": [ "test", "--", "foo", "--nocapture" ], "bin": "cargo", @@ -51,7 +53,7 @@ fn foo() { } } } - ]"#, + ]), ); } @@ -78,7 +80,7 @@ fn test_eggs() {} text_document: server.doc_id("tests/spam.rs"), position: None, }, - r#"[ + json!([ { "args": [ "test", "--package", "foo", "--test", "spam", "--", "test_eggs", "--nocapture" ], "bin": "cargo", @@ -111,6 +113,6 @@ fn test_eggs() {} } } } - ]"# + ]) ); } -- cgit v1.2.3 From 29793e7de978c9f0fa2d46bad624fc49d2506b11 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 6 Dec 2018 21:26:23 +0100 Subject: Add test for code actions --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/tests/heavy_tests/main.rs') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 63d53fb01..26f5e3f20 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -2,7 +2,9 @@ mod support; use serde_json::json; -use ra_lsp_server::req::{Runnables, RunnablesParams}; +use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; + +use languageserver_types::{Position, Range, CodeActionContext}; use crate::support::project; @@ -116,3 +118,60 @@ fn test_eggs() {} ]) ); } + +#[test] +fn test_missing_module_code_action() { + let server = project( + r#" +//- Cargo.toml +[package] +name = "foo" +version = "0.0.0" + +//- src/lib.rs +mod bar; + +fn main() {} +"#, + ); + server.wait_for_feedback("workspace loaded"); + let empty_context = || CodeActionContext { + diagnostics: Vec::new(), + only: None, + }; + server.request::( + CodeActionParams { + text_document: server.doc_id("src/lib.rs"), + range: Range::new(Position::new(0, 0), Position::new(0, 7)), + context: empty_context(), + }, + json!([ + { + "arguments": [ + { + "cursorPosition": null, + "fileSystemEdits": [ + { + "type": "createFile", + "uri": "file:///[..]/src/bar.rs" + } + ], + "label": "create module", + "sourceFileEdits": [] + } + ], + "command": "ra-lsp.applySourceChange", + "title": "create module" + } + ]), + ); + + server.request::( + CodeActionParams { + text_document: server.doc_id("src/lib.rs"), + range: Range::new(Position::new(2, 0), Position::new(2, 7)), + context: empty_context(), + }, + json!([]), + ); +} -- cgit v1.2.3