about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohann Hemmann <johann.hemmann@code.berlin>2024-01-04 13:50:54 +0100
committerJohann Hemmann <johann.hemmann@code.berlin>2024-01-04 14:01:03 +0100
commit05a3c2ff20934d8eae0545454bd20994316132c5 (patch)
treef3675f1a87b45ab80d7220468b746f4f9eb7c4ef
parentd1f4171bb6a047f2207e0c3a26f9f5fabf501a54 (diff)
downloadrust-05a3c2ff20934d8eae0545454bd20994316132c5.tar.gz
rust-05a3c2ff20934d8eae0545454bd20994316132c5.zip
Make filtering a function
-rw-r--r--crates/ide/src/rename.rs64
1 files changed, 29 insertions, 35 deletions
diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs
index 9c9c4416eee..666393ebd35 100644
--- a/crates/ide/src/rename.rs
+++ b/crates/ide/src/rename.rs
@@ -368,7 +368,7 @@ mod tests {
     use std::collections::HashMap;
 
     use expect_test::{expect, Expect};
-    use ide_db::source_change::FileSystemEdit;
+    use ide_db::source_change::{FileSystemEdit, SourceChange};
     use stdx::trim_indent;
     use test_utils::assert_eq_text;
     use text_edit::TextEdit;
@@ -421,39 +421,7 @@ mod tests {
         let (analysis, position) = fixture::position(ra_fixture);
         let source_change =
             analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError");
-
-        // file_id 1:
-        //     source_file_edits:
-        //         - Indel { insert: "foo2", delete: 4..7 }
-        //
-        // file_id 2:
-        //     file_system_edits:
-        //         MoveFile AnchoredPathBuf { anchor: FileId(2), path: "foo2.rs", }
-
-        let source_file_edits = source_change
-            .source_file_edits
-            .into_iter()
-            .map(|(a, (b, _))| (a, b.into_iter().collect::<Vec<_>>()))
-            .collect::<HashMap<_, _>>();
-
-        let file_system_edits = source_change
-            .file_system_edits
-            .into_iter()
-            .map(|a| {
-                let id = match &a {
-                    FileSystemEdit::CreateFile { .. } => unreachable!(),
-                    FileSystemEdit::MoveFile { src, .. } => src,
-                    FileSystemEdit::MoveDir { src_id, .. } => src_id,
-                };
-                (id.clone(), a)
-            })
-            .collect::<HashMap<_, _>>();
-
-        let b = format!(
-            "source_file_edits: {:#?}\nfile_system_edits: {:#?}",
-            source_file_edits, file_system_edits
-        );
-        expect.assert_eq(&b)
+        expect.assert_eq(&filter_expect(source_change))
     }
 
     fn check_expect_will_rename_file(new_name: &str, ra_fixture: &str, expect: Expect) {
@@ -462,7 +430,7 @@ mod tests {
             .will_rename_file(position.file_id, new_name)
             .unwrap()
             .expect("Expect returned a RenameError");
-        expect.assert_debug_eq(&source_change)
+        expect.assert_eq(&filter_expect(source_change))
     }
 
     fn check_prepare(ra_fixture: &str, expect: Expect) {
@@ -479,6 +447,32 @@ mod tests {
         };
     }
 
+    fn filter_expect(source_change: SourceChange) -> String {
+        let source_file_edits = source_change
+            .source_file_edits
+            .into_iter()
+            .map(|(id, (text_edit, _))| (id, text_edit.into_iter().collect::<Vec<_>>()))
+            .collect::<HashMap<_, _>>();
+
+        let file_system_edits = source_change
+            .file_system_edits
+            .into_iter()
+            .map(|file_system_edit| {
+                let id = match &file_system_edit {
+                    FileSystemEdit::CreateFile { .. } => unreachable!(),
+                    FileSystemEdit::MoveFile { src, .. } => src,
+                    FileSystemEdit::MoveDir { src_id, .. } => src_id,
+                };
+                (id.clone(), file_system_edit)
+            })
+            .collect::<HashMap<_, _>>();
+
+        format!(
+            "source_file_edits: {:#?}\nfile_system_edits: {:#?}",
+            source_file_edits, file_system_edits
+        )
+    }
+
     #[test]
     fn test_prepare_rename_namelikes() {
         check_prepare(r"fn name$0<'lifetime>() {}", expect![[r#"3..7: name"#]]);