Unnamed repository; edit this file 'description' to name the repository.
test: add test case for redundant_assoc_item quickfix
Young-Flash 2024-01-01
parent 613774e · commit 4eb3d2e
-rw-r--r--crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs97
1 files changed, 94 insertions, 3 deletions
diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
index 9992a0f82c..be2a7b9ad2 100644
--- a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
+++ b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
@@ -115,7 +115,98 @@ fn quickfix_for_redundant_assoc_item(
#[cfg(test)]
mod tests {
- use crate::tests::check_diagnostics;
+ use crate::tests::{check_diagnostics, check_fix, check_no_fix};
+
+ #[test]
+ fn quickfix_for_assoc_func() {
+ check_fix(
+ r#"
+trait Marker {
+ fn boo();
+}
+struct Foo;
+impl Marker for Foo {
+ fn$0 bar(_a: i32, _b: String) -> String {}
+ fn boo() {}
+}
+ "#,
+ r#"
+trait Marker {
+ fn bar(_a: i32, _b: String) -> String;
+ fn boo();
+}
+struct Foo;
+impl Marker for Foo {
+ fn bar(_a: i32, _b: String) -> String {}
+ fn boo() {}
+}
+ "#,
+ )
+ }
+
+ #[test]
+ fn quickfix_for_assoc_const() {
+ check_fix(
+ r#"
+trait Marker {
+ fn foo () {}
+}
+struct Foo;
+impl Marker for Foo {
+ const FLAG: bool$0 = false;
+}
+ "#,
+ r#"
+trait Marker {
+ const FLAG: bool;
+ fn foo () {}
+}
+struct Foo;
+impl Marker for Foo {
+ const FLAG: bool = false;
+}
+ "#,
+ )
+ }
+
+ #[test]
+ fn quickfix_for_assoc_type() {
+ check_fix(
+ r#"
+trait Marker {
+}
+struct Foo;
+impl Marker for Foo {
+ type T = i32;$0
+}
+ "#,
+ r#"
+trait Marker {
+ type T;
+}
+struct Foo;
+impl Marker for Foo {
+ type T = i32;
+}
+ "#,
+ )
+ }
+
+ #[test]
+ fn quickfix_dont_work() {
+ check_no_fix(
+ r#"
+ //- /dep.rs crate:dep
+ trait Marker {
+ }
+ //- /main.rs crate:main deps:dep
+ struct Foo;
+ impl dep::Marker for Foo {
+ type T = i32;$0
+ }
+ "#,
+ )
+ }
#[test]
fn trait_with_default_value() {
@@ -129,12 +220,12 @@ trait Marker {
struct Foo;
impl Marker for Foo {
type T = i32;
- //^^^^^^^^^^^^^ error: `type T` is not a member of trait `Marker`
+ //^^^^^^^^^^^^^ 💡 error: `type T` is not a member of trait `Marker`
const FLAG: bool = true;
fn bar() {}
- //^^^^^^^^^^^ error: `fn bar` is not a member of trait `Marker`
+ //^^^^^^^^^^^ 💡 error: `fn bar` is not a member of trait `Marker`
fn boo() {}
}