aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-23 13:05:13 +0000
committerAleksey Kladov <[email protected]>2019-01-23 13:05:13 +0000
commit2dbf58c579d6fe6a8acefcd9ae17eef7e984bca1 (patch)
treeeae324e5b6277358bf6d4c162cd387ac4a2a717f /crates/ra_ide_api/src/completion
parent86507c0626eb07485b21c61638673acbb3c2a9ad (diff)
move completion item tests closer to the code
this is the reason why we need marks: the tests were spread across two files, because I've forgotten that there were tests already
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs26
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs17
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs61
3 files changed, 60 insertions, 44 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 804954ee1..6bed299d2 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -121,30 +121,4 @@ mod tests {
121 ", 121 ",
122 ); 122 );
123 } 123 }
124
125 #[test]
126 fn dont_render_function_parens_in_use_item() {
127 check_reference_completion(
128 "dont_render_function_parens_in_use_item",
129 "
130 //- /lib.rs
131 mod m { pub fn foo() {} }
132 use crate::m::f<|>;
133 ",
134 )
135 }
136
137 #[test]
138 fn dont_render_function_parens_if_already_call() {
139 check_reference_completion(
140 "dont_render_function_parens_if_already_call",
141 "
142 //- /lib.rs
143 fn frobnicate() {}
144 fn main() {
145 frob<|>();
146 }
147 ",
148 )
149 }
150} 124}
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 20fc77f06..f837bb1db 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -175,21 +175,4 @@ mod tests {
175 check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }") 175 check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }")
176 } 176 }
177 177
178 #[test]
179 fn inserts_parens_for_function_calls() {
180 check_reference_completion(
181 "inserts_parens_for_function_calls1",
182 r"
183 fn no_args() {}
184 fn main() { no_<|> }
185 ",
186 );
187 check_reference_completion(
188 "inserts_parens_for_function_calls2",
189 r"
190 fn with_args(x: i32, y: String) {}
191 fn main() { with_<|> }
192 ",
193 );
194 }
195} 178}
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index 680fd8d1b..48be812a0 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -3,9 +3,10 @@ use hir::PerNs;
3use crate::completion::completion_context::CompletionContext; 3use crate::completion::completion_context::CompletionContext;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, AstNode}, 5 ast::{self, AstNode},
6 TextRange 6 TextRange,
7}; 7};
8use ra_text_edit::TextEdit; 8use ra_text_edit::TextEdit;
9use test_utils::tested_by;
9 10
10/// `CompletionItem` describes a single completion variant in the editor pop-up. 11/// `CompletionItem` describes a single completion variant in the editor pop-up.
11/// It is basically a POD with various properties. To construct a 12/// It is basically a POD with various properties. To construct a
@@ -255,6 +256,7 @@ impl Builder {
255 ) -> Builder { 256 ) -> Builder {
256 // If not an import, add parenthesis automatically. 257 // If not an import, add parenthesis automatically.
257 if ctx.use_item_syntax.is_none() && !ctx.is_call { 258 if ctx.use_item_syntax.is_none() && !ctx.is_call {
259 tested_by!(inserts_parens_for_function_calls);
258 if function.signature(ctx.db).params().is_empty() { 260 if function.signature(ctx.db).params().is_empty() {
259 self.insert_text = Some(format!("{}()$0", self.label)); 261 self.insert_text = Some(format!("{}()$0", self.label));
260 } else { 262 } else {
@@ -344,3 +346,60 @@ pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind
344 .collect(); 346 .collect();
345 assert_debug_snapshot_matches!(test_name, kind_completions); 347 assert_debug_snapshot_matches!(test_name, kind_completions);
346} 348}
349
350#[cfg(test)]
351mod tests {
352 use test_utils::covers;
353
354 use super::*;
355
356 fn check_reference_completion(code: &str, expected_completions: &str) {
357 check_completion(code, expected_completions, CompletionKind::Reference);
358 }
359
360 #[test]
361 fn inserts_parens_for_function_calls() {
362 covers!(inserts_parens_for_function_calls);
363 check_reference_completion(
364 "inserts_parens_for_function_calls1",
365 r"
366 fn no_args() {}
367 fn main() { no_<|> }
368 ",
369 );
370 check_reference_completion(
371 "inserts_parens_for_function_calls2",
372 r"
373 fn with_args(x: i32, y: String) {}
374 fn main() { with_<|> }
375 ",
376 );
377 }
378
379 #[test]
380 fn dont_render_function_parens_in_use_item() {
381 check_reference_completion(
382 "dont_render_function_parens_in_use_item",
383 "
384 //- /lib.rs
385 mod m { pub fn foo() {} }
386 use crate::m::f<|>;
387 ",
388 )
389 }
390
391 #[test]
392 fn dont_render_function_parens_if_already_call() {
393 check_reference_completion(
394 "dont_render_function_parens_if_already_call",
395 "
396 //- /lib.rs
397 fn frobnicate() {}
398 fn main() {
399 frob<|>();
400 }
401 ",
402 )
403 }
404
405}