mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Simplify changes and fix tests
This commit is contained in:
parent
9bd8336c51
commit
01bca7114c
3 changed files with 15 additions and 19 deletions
|
@ -1,9 +1,9 @@
|
|||
use ra_syntax::{SourceFile, TextUnit};
|
||||
use ra_text_edit::TextEdit;
|
||||
|
||||
use crate::LocalEdit;
|
||||
pub use test_utils::*;
|
||||
|
||||
pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
|
||||
pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<TextEdit>>(
|
||||
before: &str,
|
||||
after: &str,
|
||||
f: F,
|
||||
|
@ -11,14 +11,9 @@ pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
|
|||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let file = SourceFile::parse(&before);
|
||||
let result = f(&file, before_cursor_pos).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(before_cursor_pos)
|
||||
.expect("cursor position is affected by the edit"),
|
||||
Some(off) => off,
|
||||
};
|
||||
let actual = result.apply(&before);
|
||||
let actual_cursor_pos =
|
||||
result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit");
|
||||
let actual = add_cursor(&actual, actual_cursor_pos);
|
||||
assert_eq_text!(after, &actual);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue