@@ -15,18 +15,30 @@ pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
1515
1616pub ( crate ) fn check_assist ( assist : Handler , ra_fixture_before : & str , ra_fixture_after : & str ) {
1717 let ra_fixture_after = trim_indent ( ra_fixture_after) ;
18- check ( assist, ra_fixture_before, ExpectedResult :: After ( & ra_fixture_after) ) ;
18+ check ( assist, ra_fixture_before, ExpectedResult :: After ( & ra_fixture_after) , None ) ;
19+ }
20+
21+ // There is no way to choose what assist within a group you want to test against,
22+ // so this is here to allow you choose.
23+ pub ( crate ) fn check_assist_by_label (
24+ assist : Handler ,
25+ ra_fixture_before : & str ,
26+ ra_fixture_after : & str ,
27+ label : & str ,
28+ ) {
29+ let ra_fixture_after = trim_indent ( ra_fixture_after) ;
30+ check ( assist, ra_fixture_before, ExpectedResult :: After ( & ra_fixture_after) , Some ( label) ) ;
1931}
2032
2133// FIXME: instead of having a separate function here, maybe use
2234// `extract_ranges` and mark the target as `<target> </target>` in the
2335// fixture?
2436pub ( crate ) fn check_assist_target ( assist : Handler , ra_fixture : & str , target : & str ) {
25- check ( assist, ra_fixture, ExpectedResult :: Target ( target) ) ;
37+ check ( assist, ra_fixture, ExpectedResult :: Target ( target) , None ) ;
2638}
2739
2840pub ( crate ) fn check_assist_not_applicable ( assist : Handler , ra_fixture : & str ) {
29- check ( assist, ra_fixture, ExpectedResult :: NotApplicable ) ;
41+ check ( assist, ra_fixture, ExpectedResult :: NotApplicable , None ) ;
3042}
3143
3244fn check_doc_test ( assist_id : & str , before : & str , after : & str ) {
@@ -65,7 +77,7 @@ enum ExpectedResult<'a> {
6577 Target ( & ' a str ) ,
6678}
6779
68- fn check ( handler : Handler , before : & str , expected : ExpectedResult ) {
80+ fn check ( handler : Handler , before : & str , expected : ExpectedResult , assist_label : Option < & str > ) {
6981 let ( db, file_with_caret_id, range_or_offset) = RootDatabase :: with_range_or_offset ( before) ;
7082 let text_without_caret = db. file_text ( file_with_caret_id) . to_string ( ) ;
7183
@@ -77,7 +89,12 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) {
7789 let mut acc = Assists :: new_resolved ( & ctx) ;
7890 handler ( & mut acc, & ctx) ;
7991 let mut res = acc. finish_resolved ( ) ;
80- let assist = res. pop ( ) ;
92+
93+ let assist = match assist_label {
94+ Some ( label) => res. into_iter ( ) . find ( |resolved| resolved. assist . label == label) ,
95+ None => res. pop ( ) ,
96+ } ;
97+
8198 match ( assist, expected) {
8299 ( Some ( assist) , ExpectedResult :: After ( after) ) => {
83100 let mut source_change = assist. source_change ;
0 commit comments