File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
crates/ra_ide/src/completion Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -176,7 +176,10 @@ fn complete_return(
176176mod tests {
177177 use expect:: { expect, Expect } ;
178178
179- use crate :: completion:: { test_utils:: completion_list, CompletionKind } ;
179+ use crate :: completion:: {
180+ test_utils:: { check_edit, completion_list} ,
181+ CompletionKind ,
182+ } ;
180183
181184 fn check ( ra_fixture : & str , expect : Expect ) {
182185 let actual = completion_list ( ra_fixture, CompletionKind :: Keyword ) ;
@@ -312,6 +315,11 @@ mod tests {
312315 kw while
313316 "# ] ] ,
314317 ) ;
318+ check_edit (
319+ "else" ,
320+ r#"fn quux() { if true { () } <|> }"# ,
321+ r#"fn quux() { if true { () } else {$0} }"# ,
322+ ) ;
315323 }
316324
317325 #[ test]
Original file line number Diff line number Diff line change 11//! Runs completion for testing purposes.
22
33use hir:: Semantics ;
4+ use itertools:: Itertools ;
45use ra_syntax:: { AstNode , NodeOrToken , SyntaxElement } ;
56use stdx:: format_to;
7+ use test_utils:: assert_eq_text;
68
79use crate :: {
810 completion:: { completion_item:: CompletionKind , CompletionConfig } ,
@@ -54,6 +56,17 @@ pub(crate) fn completion_list_with_options(
5456 . collect ( )
5557}
5658
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+
5770pub ( crate ) fn check_pattern_is_applicable ( code : & str , check : fn ( SyntaxElement ) -> bool ) {
5871 let ( analysis, pos) = analysis_and_position ( code) ;
5972 analysis
You can’t perform that action at this time.
0 commit comments