aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs10
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs13
2 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index c3c6eda33..34d061f5a 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -176,7 +176,10 @@ fn complete_return(
176mod tests { 176mod tests {
177 use expect::{expect, Expect}; 177 use expect::{expect, Expect};
178 178
179 use crate::completion::{test_utils::completion_list, CompletionKind}; 179 use crate::completion::{
180 test_utils::{check_edit, completion_list},
181 CompletionKind,
182 };
180 183
181 fn check(ra_fixture: &str, expect: Expect) { 184 fn check(ra_fixture: &str, expect: Expect) {
182 let actual = completion_list(ra_fixture, CompletionKind::Keyword); 185 let actual = completion_list(ra_fixture, CompletionKind::Keyword);
@@ -312,6 +315,11 @@ mod tests {
312 kw while 315 kw while
313 "#]], 316 "#]],
314 ); 317 );
318 check_edit(
319 "else",
320 r#"fn quux() { if true { () } <|> }"#,
321 r#"fn quux() { if true { () } else {$0} }"#,
322 );
315 } 323 }
316 324
317 #[test] 325 #[test]
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs
index 5938415b3..9c036eac7 100644
--- a/crates/ra_ide/src/completion/test_utils.rs
+++ b/crates/ra_ide/src/completion/test_utils.rs
@@ -1,8 +1,10 @@
1//! Runs completion for testing purposes. 1//! Runs completion for testing purposes.
2 2
3use hir::Semantics; 3use hir::Semantics;
4use itertools::Itertools;
4use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; 5use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
5use stdx::format_to; 6use stdx::format_to;
7use test_utils::assert_eq_text;
6 8
7use crate::{ 9use crate::{
8 completion::{completion_item::CompletionKind, CompletionConfig}, 10 completion::{completion_item::CompletionKind, CompletionConfig},
@@ -54,6 +56,17 @@ pub(crate) fn completion_list_with_options(
54 .collect() 56 .collect()
55} 57}
56 58
59pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
60 let (analysis, position) = analysis_and_position(ra_fixture_before);
61 let completions: Vec<CompletionItem> =
62 analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into();
63 let (completion,) =
64 completions.into_iter().filter(|it| it.label() == what).collect_tuple().unwrap();
65 let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
66 completion.text_edit().apply(&mut actual);
67 assert_eq_text!(ra_fixture_after, &actual)
68}
69
57pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { 70pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
58 let (analysis, pos) = analysis_and_position(code); 71 let (analysis, pos) = analysis_and_position(code);
59 analysis 72 analysis