Switch to Vec, because we do want to have duplicate keys

This commit is contained in:
Johann Hemmann 2024-01-04 13:56:53 +01:00
parent dea149d733
commit f2b872a3c5

View File

@ -365,8 +365,6 @@ fn text_edit_from_self_param(self_param: &ast::SelfParam, new_name: &str) -> Opt
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::collections::BTreeMap;
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use ide_db::source_change::{FileSystemEdit, SourceChange}; use ide_db::source_change::{FileSystemEdit, SourceChange};
use stdx::trim_indent; use stdx::trim_indent;
@ -452,7 +450,7 @@ mod tests {
.source_file_edits .source_file_edits
.into_iter() .into_iter()
.map(|(id, (text_edit, _))| (id, text_edit.into_iter().collect::<Vec<_>>())) .map(|(id, (text_edit, _))| (id, text_edit.into_iter().collect::<Vec<_>>()))
.collect::<BTreeMap<_, _>>(); .collect::<Vec<_>>();
let file_system_edits = source_change let file_system_edits = source_change
.file_system_edits .file_system_edits
@ -465,7 +463,7 @@ mod tests {
}; };
(id.clone(), file_system_edit) (id.clone(), file_system_edit)
}) })
.collect::<BTreeMap<_, _>>(); .collect::<Vec<_>>();
format!( format!(
"source_file_edits: {:#?}\nfile_system_edits: {:#?}", "source_file_edits: {:#?}\nfile_system_edits: {:#?}",
@ -945,31 +943,37 @@ mod foo$0;
// empty // empty
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
1, FileId(
): [ 1,
Indel { ),
insert: "foo2", [
delete: 4..7, Indel {
}, insert: "foo2",
], delete: 4..7,
} },
file_system_edits: { ],
FileId( ),
2, ]
): MoveFile { file_system_edits: [
src: FileId( (
FileId(
2, 2,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
2, 2,
), ),
path: "foo2.rs", dst: AnchoredPathBuf {
anchor: FileId(
2,
),
path: "foo2.rs",
},
}, },
}, ),
}"#]], ]"#]],
); );
} }
@ -990,39 +994,48 @@ pub struct FooContent;
use crate::foo$0::FooContent; use crate::foo$0::FooContent;
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "quux", [
delete: 8..11, Indel {
}, insert: "quux",
], delete: 8..11,
FileId( },
2, ],
): [ ),
Indel { (
insert: "quux", FileId(
delete: 11..14, 2,
}, ),
], [
} Indel {
file_system_edits: { insert: "quux",
FileId( delete: 11..14,
1, },
): MoveFile { ],
src: FileId( ),
]
file_system_edits: [
(
FileId(
1, 1,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
1, 1,
), ),
path: "quux.rs", dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "quux.rs",
},
}, },
}, ),
}"#]], ]"#]],
); );
} }
@ -1037,37 +1050,43 @@ mod fo$0o;
// empty // empty
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "foo2", [
delete: 4..7, Indel {
}, insert: "foo2",
], delete: 4..7,
} },
file_system_edits: { ],
FileId( ),
1, ]
): MoveDir { file_system_edits: [
src: AnchoredPathBuf { (
anchor: FileId( FileId(
1,
),
path: "../foo",
},
src_id: FileId(
1, 1,
), ),
dst: AnchoredPathBuf { MoveDir {
anchor: FileId( src: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "../foo",
},
src_id: FileId(
1, 1,
), ),
path: "../foo2", dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "../foo2",
},
}, },
}, ),
}"#]], ]"#]],
); );
} }
@ -1083,31 +1102,37 @@ mod outer { mod fo$0o; }
// empty // empty
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "bar", [
delete: 16..19, Indel {
}, insert: "bar",
], delete: 16..19,
} },
file_system_edits: { ],
FileId( ),
1, ]
): MoveFile { file_system_edits: [
src: FileId( (
FileId(
1, 1,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
1, 1,
), ),
path: "bar.rs", dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "bar.rs",
},
}, },
}, ),
}"#]], ]"#]],
); );
} }
@ -1152,39 +1177,48 @@ pub mod foo$0;
// pub fn fun() {} // pub fn fun() {}
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "foo2", [
delete: 27..30, Indel {
}, insert: "foo2",
], delete: 27..30,
FileId( },
1, ],
): [ ),
Indel { (
insert: "foo2", FileId(
delete: 8..11, 1,
}, ),
], [
} Indel {
file_system_edits: { insert: "foo2",
FileId( delete: 8..11,
2, },
): MoveFile { ],
src: FileId( ),
]
file_system_edits: [
(
FileId(
2, 2,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
2, 2,
), ),
path: "foo2.rs", dst: AnchoredPathBuf {
anchor: FileId(
2,
),
path: "foo2.rs",
},
}, },
}, ),
}"#]], ]"#]],
); );
} }
@ -1213,37 +1247,59 @@ mod quux;
// empty // empty
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "foo2", [
delete: 4..7, Indel {
}, insert: "foo2",
], delete: 4..7,
} },
file_system_edits: { ],
FileId( ),
1, ]
): MoveDir { file_system_edits: [
src: AnchoredPathBuf { (
anchor: FileId( FileId(
1,
),
path: "foo",
},
src_id: FileId(
1, 1,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
1, 1,
), ),
path: "foo2", dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "foo2.rs",
},
}, },
}, ),
}"#]], (
FileId(
1,
),
MoveDir {
src: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "foo",
},
src_id: FileId(
1,
),
dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "foo2",
},
},
),
]"#]],
) )
} }
#[test] #[test]
@ -1310,8 +1366,8 @@ fn foo() {}
mod bar$0; mod bar$0;
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: {} source_file_edits: []
file_system_edits: {}"#]], file_system_edits: []"#]],
) )
} }
@ -1332,41 +1388,63 @@ pub mod bar;
pub fn baz() {} pub fn baz() {}
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "r#fn", [
delete: 4..7, Indel {
}, insert: "r#fn",
Indel { delete: 4..7,
insert: "r#fn", },
delete: 22..25, Indel {
}, insert: "r#fn",
], delete: 22..25,
} },
file_system_edits: { ],
FileId( ),
1, ]
): MoveDir { file_system_edits: [
src: AnchoredPathBuf { (
anchor: FileId( FileId(
1,
),
path: "foo",
},
src_id: FileId(
1, 1,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
1, 1,
), ),
path: "fn", dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "fn.rs",
},
}, },
}, ),
}"#]], (
FileId(
1,
),
MoveDir {
src: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "foo",
},
src_id: FileId(
1,
),
dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "fn",
},
},
),
]"#]],
); );
} }
@ -1387,41 +1465,63 @@ pub mod bar;
pub fn baz() {} pub fn baz() {}
"#, "#,
expect![[r#" expect![[r#"
source_file_edits: { source_file_edits: [
FileId( (
0, FileId(
): [ 0,
Indel { ),
insert: "foo", [
delete: 4..8, Indel {
}, insert: "foo",
Indel { delete: 4..8,
insert: "foo", },
delete: 23..27, Indel {
}, insert: "foo",
], delete: 23..27,
} },
file_system_edits: { ],
FileId( ),
1, ]
): MoveDir { file_system_edits: [
src: AnchoredPathBuf { (
anchor: FileId( FileId(
1,
),
path: "fn",
},
src_id: FileId(
1, 1,
), ),
dst: AnchoredPathBuf { MoveFile {
anchor: FileId( src: FileId(
1, 1,
), ),
path: "foo", dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "foo.rs",
},
}, },
}, ),
}"#]], (
FileId(
1,
),
MoveDir {
src: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "fn",
},
src_id: FileId(
1,
),
dst: AnchoredPathBuf {
anchor: FileId(
1,
),
path: "foo",
},
},
),
]"#]],
); );
} }