2019-09-30 08:58:53 +00:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2019-02-03 18:26:35 +00:00
|
|
|
use ra_syntax::{SourceFile, TextUnit};
|
2019-03-22 16:10:20 +00:00
|
|
|
use ra_text_edit::TextEdit;
|
2018-08-28 11:47:12 +00:00
|
|
|
|
2018-12-06 18:16:37 +00:00
|
|
|
pub use test_utils::*;
|
|
|
|
|
2019-03-22 16:10:20 +00:00
|
|
|
pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<TextEdit>>(
|
2018-11-07 15:32:33 +00:00
|
|
|
before: &str,
|
|
|
|
after: &str,
|
|
|
|
f: F,
|
|
|
|
) {
|
2018-08-28 11:47:12 +00:00
|
|
|
let (before_cursor_pos, before) = extract_offset(before);
|
2019-05-28 15:46:11 +00:00
|
|
|
let file = SourceFile::parse(&before).ok().unwrap();
|
2018-08-28 11:47:12 +00:00
|
|
|
let result = f(&file, before_cursor_pos).expect("code action is not applicable");
|
2019-03-22 16:10:20 +00:00
|
|
|
let actual = result.apply(&before);
|
|
|
|
let actual_cursor_pos =
|
|
|
|
result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit");
|
2018-08-28 11:47:12 +00:00
|
|
|
let actual = add_cursor(&actual, actual_cursor_pos);
|
|
|
|
assert_eq_text!(after, &actual);
|
|
|
|
}
|