Skip to content

Commit 5074486

Browse files
committed
Fix rename test fixtures not accounting for multi file edits
1 parent 9bd9a17 commit 5074486

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

crates/ide/src/rename.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ mod tests {
372372
use test_utils::assert_eq_text;
373373
use text_edit::TextEdit;
374374

375-
use crate::{fixture, FileId};
375+
use crate::fixture;
376376

377377
use super::{RangeInfo, RenameError};
378378

@@ -400,18 +400,17 @@ mod tests {
400400
match rename_result {
401401
Ok(source_change) => {
402402
let mut text_edit_builder = TextEdit::builder();
403-
let mut file_id: Option<FileId> = None;
404-
for edit in source_change.source_file_edits {
405-
file_id = Some(edit.0);
406-
for indel in edit.1 .0.into_iter() {
407-
text_edit_builder.replace(indel.delete, indel.insert);
408-
}
409-
}
410-
if let Some(file_id) = file_id {
411-
let mut result = analysis.file_text(file_id).unwrap().to_string();
412-
text_edit_builder.finish().apply(&mut result);
413-
assert_eq_text!(ra_fixture_after, &*result);
403+
let (&file_id, edit) = match source_change.source_file_edits.len() {
404+
0 => return,
405+
1 => source_change.source_file_edits.iter().next().unwrap(),
406+
_ => (&position.file_id, &source_change.source_file_edits[&position.file_id]),
407+
};
408+
for indel in edit.0.iter() {
409+
text_edit_builder.replace(indel.delete, indel.insert.clone());
414410
}
411+
let mut result = analysis.file_text(file_id).unwrap().to_string();
412+
text_edit_builder.finish().apply(&mut result);
413+
assert_eq_text!(ra_fixture_after, &*result);
415414
}
416415
Err(err) => {
417416
if ra_fixture_after.starts_with("error:") {
@@ -2649,7 +2648,7 @@ pub struct S;
26492648
//- /main.rs crate:main deps:lib new_source_root:local
26502649
use lib::S$0;
26512650
"#,
2652-
"use lib::Baz;",
2651+
"use lib::Baz;\n",
26532652
);
26542653
}
26552654

0 commit comments

Comments
 (0)