mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
introduce variable
This commit is contained in:
parent
47e8b80e9b
commit
bb64edf8ba
6 changed files with 72 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
use libsyntax2::{File, TextUnit};
|
||||
use libsyntax2::{File, TextUnit, TextRange};
|
||||
pub use _test_utils::*;
|
||||
use LocalEdit;
|
||||
|
||||
|
@ -18,3 +18,20 @@ pub fn check_action<F: Fn(&File, TextUnit) -> Option<LocalEdit>> (
|
|||
let actual = add_cursor(&actual, actual_cursor_pos);
|
||||
assert_eq_text!(after, &actual);
|
||||
}
|
||||
|
||||
pub fn check_action_range<F: Fn(&File, TextRange) -> Option<LocalEdit>> (
|
||||
before: &str,
|
||||
after: &str,
|
||||
f: F,
|
||||
) {
|
||||
let (range, before) = extract_range(before);
|
||||
let file = File::parse(&before);
|
||||
let result = f(&file, range).expect("code action is not applicable");
|
||||
let actual = result.edit.apply(&before);
|
||||
let actual_cursor_pos = match result.cursor_position {
|
||||
None => result.edit.apply_to_offset(range.start()).unwrap(),
|
||||
Some(off) => off,
|
||||
};
|
||||
let actual = add_cursor(&actual, actual_cursor_pos);
|
||||
assert_eq_text!(after, &actual);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue