2019-10-25 06:16:46 -05:00
|
|
|
//! Each assist definition has a special comment, which specifies docs and
|
|
|
|
//! example.
|
|
|
|
//!
|
|
|
|
//! We collect all the example and write the as tests in this module.
|
|
|
|
|
|
|
|
mod generated;
|
|
|
|
|
|
|
|
use hir::mock::MockDatabase;
|
|
|
|
use ra_db::FileRange;
|
2019-10-26 11:58:18 -05:00
|
|
|
use test_utils::{assert_eq_text, extract_range_or_offset};
|
2019-10-25 06:16:46 -05:00
|
|
|
|
|
|
|
fn check(assist_id: &str, before: &str, after: &str) {
|
2019-10-26 11:58:18 -05:00
|
|
|
let (selection, before) = extract_range_or_offset(before);
|
2019-10-25 06:16:46 -05:00
|
|
|
let (db, _source_root, file_id) = MockDatabase::with_single_file(&before);
|
2019-10-26 11:58:18 -05:00
|
|
|
let frange = FileRange { file_id, range: selection.into() };
|
2019-10-25 06:16:46 -05:00
|
|
|
|
2019-10-25 15:38:15 -05:00
|
|
|
let (_assist_id, action) = crate::assists(&db, frange)
|
|
|
|
.into_iter()
|
|
|
|
.find(|(id, _)| id.id.0 == assist_id)
|
2019-10-27 08:56:53 -05:00
|
|
|
.unwrap_or_else(|| {
|
|
|
|
panic!(
|
|
|
|
"\n\nAssist is not applicable: {}\nAvailable assists: {}",
|
|
|
|
assist_id,
|
|
|
|
crate::assists(&db, frange)
|
|
|
|
.into_iter()
|
|
|
|
.map(|(id, _)| id.id.0)
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", ")
|
|
|
|
)
|
|
|
|
});
|
2019-10-25 06:16:46 -05:00
|
|
|
|
|
|
|
let actual = action.edit.apply(&before);
|
|
|
|
assert_eq_text!(after, &actual);
|
|
|
|
}
|