aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/doc_tests.rs
blob: 0ccf9d7308e866a4b55b75b854ba705b78dae940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! 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;
use test_utils::{assert_eq_text, extract_range_or_offset};

fn check(assist_id: &str, before: &str, after: &str) {
    let (selection, before) = extract_range_or_offset(before);
    let (db, _source_root, file_id) = MockDatabase::with_single_file(&before);
    let frange = FileRange { file_id, range: selection.into() };

    let (_assist_id, action) = crate::assists(&db, frange)
        .into_iter()
        .find(|(id, _)| id.id.0 == assist_id)
        .unwrap_or_else(|| panic!("Assist {:?} is not applicable", assist_id));

    let actual = action.edit.apply(&before);
    assert_eq_text!(after, &actual);
}