mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-14 09:36:06 +00:00
Cleanup
This commit is contained in:
parent
5f57491c98
commit
ef0da3bbec
@ -166,16 +166,28 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::test_utils::{assert_eq_text, check_action, extract_range};
|
||||
use ra_syntax::SourceFile;
|
||||
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn check_join_lines(before: &str, after: &str) {
|
||||
check_action(before, after, |file, offset| {
|
||||
let range = TextRange::empty(offset);
|
||||
let res = join_lines(file, range);
|
||||
Some(res)
|
||||
})
|
||||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let file = SourceFile::parse(&before).ok().unwrap();
|
||||
|
||||
let range = TextRange::empty(before_cursor_pos);
|
||||
let result = join_lines(&file, range);
|
||||
|
||||
let actual = {
|
||||
let mut actual = before.to_string();
|
||||
result.apply(&mut actual);
|
||||
actual
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -42,9 +42,6 @@ mod inlay_hints;
|
||||
mod expand_macro;
|
||||
mod ssr;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_utils;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_cfg::CfgOptions;
|
||||
|
@ -1,25 +0,0 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use ra_syntax::{SourceFile, TextSize};
|
||||
use ra_text_edit::TextEdit;
|
||||
|
||||
pub(crate) use test_utils::*;
|
||||
|
||||
pub(crate) fn check_action<F: Fn(&SourceFile, TextSize) -> Option<TextEdit>>(
|
||||
before: &str,
|
||||
after: &str,
|
||||
f: F,
|
||||
) {
|
||||
let (before_cursor_pos, before) = extract_offset(before);
|
||||
let file = SourceFile::parse(&before).ok().unwrap();
|
||||
let result = f(&file, before_cursor_pos).expect("code action is not applicable");
|
||||
let actual = {
|
||||
let mut actual = before.to_string();
|
||||
result.apply(&mut actual);
|
||||
actual
|
||||
};
|
||||
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…
Reference in New Issue
Block a user