diff options
Diffstat (limited to 'crates/ra_ide/src/completion/test_utils.rs')
-rw-r--r-- | crates/ra_ide/src/completion/test_utils.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index 5c01654cc..9c036eac7 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs | |||
@@ -1,7 +1,10 @@ | |||
1 | //! Runs completion for testing purposes. | 1 | //! Runs completion for testing purposes. |
2 | 2 | ||
3 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use itertools::Itertools; | ||
4 | use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; | 5 | use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; |
6 | use stdx::format_to; | ||
7 | use test_utils::assert_eq_text; | ||
5 | 8 | ||
6 | use crate::{ | 9 | use crate::{ |
7 | completion::{completion_item::CompletionKind, CompletionConfig}, | 10 | completion::{completion_item::CompletionKind, CompletionConfig}, |
@@ -42,10 +45,28 @@ pub(crate) fn completion_list_with_options( | |||
42 | kind_completions.sort_by_key(|c| c.label().to_owned()); | 45 | kind_completions.sort_by_key(|c| c.label().to_owned()); |
43 | kind_completions | 46 | kind_completions |
44 | .into_iter() | 47 | .into_iter() |
45 | .map(|it| format!("{} {}\n", it.kind().unwrap().tag(), it.label())) | 48 | .map(|it| { |
49 | let mut buf = format!("{} {}", it.kind().unwrap().tag(), it.label()); | ||
50 | if let Some(detail) = it.detail() { | ||
51 | format_to!(buf, " {}", detail); | ||
52 | } | ||
53 | format_to!(buf, "\n"); | ||
54 | buf | ||
55 | }) | ||
46 | .collect() | 56 | .collect() |
47 | } | 57 | } |
48 | 58 | ||
59 | pub(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 | |||
49 | pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { | 70 | pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { |
50 | let (analysis, pos) = analysis_and_position(code); | 71 | let (analysis, pos) = analysis_and_position(code); |
51 | analysis | 72 | analysis |