mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #6509
6509: Support multi-file assist tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
6b92cc4384
2 changed files with 55 additions and 5 deletions
|
@ -345,6 +345,43 @@ fn another_fn() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_several_files() {
|
||||
check_assist(
|
||||
extract_struct_from_enum_variant,
|
||||
r#"
|
||||
//- /main.rs
|
||||
enum E {
|
||||
<|>V(i32, i32)
|
||||
}
|
||||
mod foo;
|
||||
|
||||
//- /foo.rs
|
||||
use crate::E;
|
||||
fn f() {
|
||||
let e = E::V(9, 2);
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
//- /main.rs
|
||||
struct V(pub i32, pub i32);
|
||||
|
||||
enum E {
|
||||
V(V)
|
||||
}
|
||||
mod foo;
|
||||
|
||||
//- /foo.rs
|
||||
use V;
|
||||
|
||||
use crate::E;
|
||||
fn f() {
|
||||
let e = E::V(V(9, 2));
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
fn check_not_applicable(ra_fixture: &str) {
|
||||
let fixture =
|
||||
format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
|
||||
|
|
|
@ -7,7 +7,7 @@ use syntax::TextRange;
|
|||
use test_utils::{assert_eq_text, extract_offset, extract_range};
|
||||
|
||||
use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};
|
||||
use stdx::trim_indent;
|
||||
use stdx::{format_to, trim_indent};
|
||||
|
||||
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
|
||||
RootDatabase::with_single_file(text)
|
||||
|
@ -98,11 +98,24 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
|
|||
match (assist, expected) {
|
||||
(Some(assist), ExpectedResult::After(after)) => {
|
||||
let mut source_change = assist.source_change;
|
||||
let change = source_change.source_file_edits.pop().unwrap();
|
||||
assert!(!source_change.source_file_edits.is_empty());
|
||||
let skip_header = source_change.source_file_edits.len() == 1;
|
||||
source_change.source_file_edits.sort_by_key(|it| it.file_id);
|
||||
|
||||
let mut actual = db.file_text(change.file_id).as_ref().to_owned();
|
||||
change.edit.apply(&mut actual);
|
||||
assert_eq_text!(after, &actual);
|
||||
let mut buf = String::new();
|
||||
for source_file_edit in source_change.source_file_edits {
|
||||
let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned();
|
||||
source_file_edit.edit.apply(&mut text);
|
||||
if !skip_header {
|
||||
let sr = db.file_source_root(source_file_edit.file_id);
|
||||
let sr = db.source_root(sr);
|
||||
let path = sr.path_for_file(&source_file_edit.file_id).unwrap();
|
||||
format_to!(buf, "//- {}\n", path)
|
||||
}
|
||||
buf.push_str(&text);
|
||||
}
|
||||
|
||||
assert_eq_text!(after, &buf);
|
||||
}
|
||||
(Some(assist), ExpectedResult::Target(target)) => {
|
||||
let range = assist.assist.target;
|
||||
|
|
Loading…
Reference in a new issue