mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
rename ra_editor -> ra_ide_api_light
This commit is contained in:
parent
4f4f7933b1
commit
1967884d68
18 changed files with 0 additions and 0 deletions
41
crates/ra_ide_api_light/src/test_utils.rs
Normal file
41
crates/ra_ide_api_light/src/test_utils.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use ra_syntax::{SourceFile, TextRange, TextUnit};
|
||||
|
||||
use crate::LocalEdit;
|
||||
pub use test_utils::*;
|
||||
|
||||
pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
|
||||
before: &str,
|
||||
after: &str,
|
||||
f: F,
|
||||
) {
|
||||
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 = add_cursor(&actual, actual_cursor_pos);
|
||||
assert_eq_text!(after, &actual);
|
||||
}
|
||||
|
||||
pub fn check_action_range<F: Fn(&SourceFile, TextRange) -> Option<LocalEdit>>(
|
||||
before: &str,
|
||||
after: &str,
|
||||
f: F,
|
||||
) {
|
||||
let (range, before) = extract_range(before);
|
||||
let file = SourceFile::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