diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/doc_tests.rs | 39 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/tests.rs | 28 | ||||
-rw-r--r-- | crates/ra_assists/src/tests/generated.rs (renamed from crates/ra_assists/src/doc_tests/generated.rs) | 0 |
4 files changed, 28 insertions, 41 deletions
diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs deleted file mode 100644 index 5eabb33d0..000000000 --- a/crates/ra_assists/src/doc_tests.rs +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | //! Each assist definition has a special comment, which specifies docs and | ||
2 | //! example. | ||
3 | //! | ||
4 | //! We collect all the example and write the as tests in this module. | ||
5 | |||
6 | mod generated; | ||
7 | |||
8 | use ra_db::FileRange; | ||
9 | use test_utils::{assert_eq_text, extract_range_or_offset}; | ||
10 | |||
11 | use crate::resolved_assists; | ||
12 | |||
13 | fn check(assist_id: &str, before: &str, after: &str) { | ||
14 | let (selection, before) = extract_range_or_offset(before); | ||
15 | let (db, file_id) = crate::tests::with_single_file(&before); | ||
16 | let frange = FileRange { file_id, range: selection.into() }; | ||
17 | |||
18 | let assist = resolved_assists(&db, frange) | ||
19 | .into_iter() | ||
20 | .find(|assist| assist.label.id.0 == assist_id) | ||
21 | .unwrap_or_else(|| { | ||
22 | panic!( | ||
23 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", | ||
24 | assist_id, | ||
25 | resolved_assists(&db, frange) | ||
26 | .into_iter() | ||
27 | .map(|assist| assist.label.id.0) | ||
28 | .collect::<Vec<_>>() | ||
29 | .join(", ") | ||
30 | ) | ||
31 | }); | ||
32 | |||
33 | let actual = { | ||
34 | let mut actual = before.clone(); | ||
35 | assist.action.edit.apply(&mut actual); | ||
36 | actual | ||
37 | }; | ||
38 | assert_eq_text!(after, &actual); | ||
39 | } | ||
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index b84d60c77..b794b021d 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -13,8 +13,6 @@ macro_rules! eprintln { | |||
13 | mod assist_ctx; | 13 | mod assist_ctx; |
14 | mod marks; | 14 | mod marks; |
15 | #[cfg(test)] | 15 | #[cfg(test)] |
16 | mod doc_tests; | ||
17 | #[cfg(test)] | ||
18 | mod tests; | 16 | mod tests; |
19 | pub mod utils; | 17 | pub mod utils; |
20 | pub mod ast_transform; | 18 | pub mod ast_transform; |
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), |
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/tests/generated.rs index 6696cc832..6696cc832 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/tests/generated.rs | |||