aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/doc_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/doc_tests.rs')
-rw-r--r--crates/ra_assists/src/doc_tests.rs23
1 files changed, 23 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..88e901517
--- /dev/null
+++ b/crates/ra_assists/src/doc_tests.rs
@@ -0,0 +1,23 @@
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
6mod generated;
7
8use hir::mock::MockDatabase;
9use ra_db::FileRange;
10use ra_syntax::TextRange;
11use test_utils::{assert_eq_text, extract_offset};
12
13fn check(assist_id: &str, before: &str, after: &str) {
14 let (before_cursor_pos, before) = extract_offset(before);
15 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before);
16 let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
17
18 let (_assist_id, action) =
19 crate::assists(&db, frange).into_iter().find(|(id, _)| id.id.0 == assist_id).unwrap();
20
21 let actual = action.edit.apply(&before);
22 assert_eq_text!(after, &actual);
23}