diff options
Diffstat (limited to 'crates/ra_assists/src/doc_tests.rs')
-rw-r--r-- | crates/ra_assists/src/doc_tests.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs new file mode 100644 index 000000000..6e1e3de84 --- /dev/null +++ b/crates/ra_assists/src/doc_tests.rs | |||
@@ -0,0 +1,34 @@ | |||
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 hir::mock::MockDatabase; | ||
9 | use ra_db::FileRange; | ||
10 | use test_utils::{assert_eq_text, extract_range_or_offset}; | ||
11 | |||
12 | fn check(assist_id: &str, before: &str, after: &str) { | ||
13 | let (selection, before) = extract_range_or_offset(before); | ||
14 | let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); | ||
15 | let frange = FileRange { file_id, range: selection.into() }; | ||
16 | |||
17 | let (_assist_id, action) = crate::assists(&db, frange) | ||
18 | .into_iter() | ||
19 | .find(|(id, _)| id.id.0 == assist_id) | ||
20 | .unwrap_or_else(|| { | ||
21 | panic!( | ||
22 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", | ||
23 | assist_id, | ||
24 | crate::assists(&db, frange) | ||
25 | .into_iter() | ||
26 | .map(|(id, _)| id.id.0) | ||
27 | .collect::<Vec<_>>() | ||
28 | .join(", ") | ||
29 | ) | ||
30 | }); | ||
31 | |||
32 | let actual = action.edit.apply(&before); | ||
33 | assert_eq_text!(after, &actual); | ||
34 | } | ||