diff options
author | Aleksey Kladov <[email protected]> | 2019-10-25 12:16:46 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-25 12:47:48 +0100 |
commit | 0dd35ff2b2ceffdb926953fdacc7d30e1968047d (patch) | |
tree | a8bcab00ef1c434e56845034f22a5595d119dea7 /crates/ra_assists/src/doc_tests.rs | |
parent | 518f99e16b993e3414a81181c8bad7a89e590ece (diff) |
auto-generate assists docs and tests
Diffstat (limited to 'crates/ra_assists/src/doc_tests.rs')
-rw-r--r-- | crates/ra_assists/src/doc_tests.rs | 23 |
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 | |||
6 | mod generated; | ||
7 | |||
8 | use hir::mock::MockDatabase; | ||
9 | use ra_db::FileRange; | ||
10 | use ra_syntax::TextRange; | ||
11 | use test_utils::{assert_eq_text, extract_offset}; | ||
12 | |||
13 | fn 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 | } | ||