diff options
Diffstat (limited to 'crates/ra_assists/src/tests.rs')
-rw-r--r-- | crates/ra_assists/src/tests.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index ca3096a43..97744904a 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs | |||
@@ -34,6 +34,34 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { | |||
34 | check(assist, ra_fixture, ExpectedResult::NotApplicable); | 34 | check(assist, ra_fixture, ExpectedResult::NotApplicable); |
35 | } | 35 | } |
36 | 36 | ||
37 | fn check_doc_test(assist_id: &str, before: &str, after: &str) { | ||
38 | let (selection, before) = extract_range_or_offset(before); | ||
39 | let (db, file_id) = crate::tests::with_single_file(&before); | ||
40 | let frange = FileRange { file_id, range: selection.into() }; | ||
41 | |||
42 | let assist = resolved_assists(&db, frange) | ||
43 | .into_iter() | ||
44 | .find(|assist| assist.label.id.0 == assist_id) | ||
45 | .unwrap_or_else(|| { | ||
46 | panic!( | ||
47 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", | ||
48 | assist_id, | ||
49 | resolved_assists(&db, frange) | ||
50 | .into_iter() | ||
51 | .map(|assist| assist.label.id.0) | ||
52 | .collect::<Vec<_>>() | ||
53 | .join(", ") | ||
54 | ) | ||
55 | }); | ||
56 | |||
57 | let actual = { | ||
58 | let mut actual = before.clone(); | ||
59 | assist.action.edit.apply(&mut actual); | ||
60 | actual | ||
61 | }; | ||
62 | assert_eq_text!(after, &actual); | ||
63 | } | ||
64 | |||
37 | enum ExpectedResult<'a> { | 65 | enum ExpectedResult<'a> { |
38 | NotApplicable, | 66 | NotApplicable, |
39 | After(&'a str), | 67 | After(&'a str), |