aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests/heavy_tests/main.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-06 20:57:04 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-06 20:57:04 +0000
commit66f656134f349f943905cfe44f5005263dc635f9 (patch)
tree513b56d0c4757f37fa318b964ac1f630e246680b /crates/ra_lsp_server/tests/heavy_tests/main.rs
parent8e60e751cbcfa47c7bed788dfe2ab5cebfcb78b3 (diff)
parent29793e7de978c9f0fa2d46bad624fc49d2506b11 (diff)
Merge #261
261: Add heavy test for code actions r=matklad a=flodiebold Here's the test for the code actions; I didn't find anything fitting on crates.io ([assert-json-diff](https://crates.io/crates/assert-json-diff) looks kind of nice, but doesn't have anything like the wildcards), so I copied the cargo code as you suggested. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests/main.rs')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs71
1 files changed, 66 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index cbc0c8844..26f5e3f20 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -1,6 +1,10 @@
1mod support; 1mod support;
2 2
3use ra_lsp_server::req::{Runnables, RunnablesParams}; 3use serde_json::json;
4
5use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams};
6
7use languageserver_types::{Position, Range, CodeActionContext};
4 8
5use crate::support::project; 9use crate::support::project;
6 10
@@ -21,7 +25,7 @@ fn foo() {
21 text_document: server.doc_id("lib.rs"), 25 text_document: server.doc_id("lib.rs"),
22 position: None, 26 position: None,
23 }, 27 },
24 r#"[ 28 json!([
25 { 29 {
26 "args": [ "test", "--", "foo", "--nocapture" ], 30 "args": [ "test", "--", "foo", "--nocapture" ],
27 "bin": "cargo", 31 "bin": "cargo",
@@ -51,7 +55,7 @@ fn foo() {
51 } 55 }
52 } 56 }
53 } 57 }
54 ]"#, 58 ]),
55 ); 59 );
56} 60}
57 61
@@ -78,7 +82,7 @@ fn test_eggs() {}
78 text_document: server.doc_id("tests/spam.rs"), 82 text_document: server.doc_id("tests/spam.rs"),
79 position: None, 83 position: None,
80 }, 84 },
81 r#"[ 85 json!([
82 { 86 {
83 "args": [ "test", "--package", "foo", "--test", "spam", "--", "test_eggs", "--nocapture" ], 87 "args": [ "test", "--package", "foo", "--test", "spam", "--", "test_eggs", "--nocapture" ],
84 "bin": "cargo", 88 "bin": "cargo",
@@ -111,6 +115,63 @@ fn test_eggs() {}
111 } 115 }
112 } 116 }
113 } 117 }
114 ]"# 118 ])
119 );
120}
121
122#[test]
123fn test_missing_module_code_action() {
124 let server = project(
125 r#"
126//- Cargo.toml
127[package]
128name = "foo"
129version = "0.0.0"
130
131//- src/lib.rs
132mod bar;
133
134fn main() {}
135"#,
136 );
137 server.wait_for_feedback("workspace loaded");
138 let empty_context = || CodeActionContext {
139 diagnostics: Vec::new(),
140 only: None,
141 };
142 server.request::<CodeActionRequest>(
143 CodeActionParams {
144 text_document: server.doc_id("src/lib.rs"),
145 range: Range::new(Position::new(0, 0), Position::new(0, 7)),
146 context: empty_context(),
147 },
148 json!([
149 {
150 "arguments": [
151 {
152 "cursorPosition": null,
153 "fileSystemEdits": [
154 {
155 "type": "createFile",
156 "uri": "file:///[..]/src/bar.rs"
157 }
158 ],
159 "label": "create module",
160 "sourceFileEdits": []
161 }
162 ],
163 "command": "ra-lsp.applySourceChange",
164 "title": "create module"
165 }
166 ]),
167 );
168
169 server.request::<CodeActionRequest>(
170 CodeActionParams {
171 text_document: server.doc_id("src/lib.rs"),
172 range: Range::new(Position::new(2, 0), Position::new(2, 7)),
173 context: empty_context(),
174 },
175 json!([]),
115 ); 176 );
116} 177}