Skip to content

Commit 4eb3d2e

Browse files
committed
test: add test case for redundant_assoc_item quickfix
1 parent 613774e commit 4eb3d2e

File tree

1 file changed

+94
-3
lines changed

1 file changed

+94
-3
lines changed

crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,98 @@ fn quickfix_for_redundant_assoc_item(
115115

116116
#[cfg(test)]
117117
mod tests {
118-
use crate::tests::check_diagnostics;
118+
use crate::tests::{check_diagnostics, check_fix, check_no_fix};
119+
120+
#[test]
121+
fn quickfix_for_assoc_func() {
122+
check_fix(
123+
r#"
124+
trait Marker {
125+
fn boo();
126+
}
127+
struct Foo;
128+
impl Marker for Foo {
129+
fn$0 bar(_a: i32, _b: String) -> String {}
130+
fn boo() {}
131+
}
132+
"#,
133+
r#"
134+
trait Marker {
135+
fn bar(_a: i32, _b: String) -> String;
136+
fn boo();
137+
}
138+
struct Foo;
139+
impl Marker for Foo {
140+
fn bar(_a: i32, _b: String) -> String {}
141+
fn boo() {}
142+
}
143+
"#,
144+
)
145+
}
146+
147+
#[test]
148+
fn quickfix_for_assoc_const() {
149+
check_fix(
150+
r#"
151+
trait Marker {
152+
fn foo () {}
153+
}
154+
struct Foo;
155+
impl Marker for Foo {
156+
const FLAG: bool$0 = false;
157+
}
158+
"#,
159+
r#"
160+
trait Marker {
161+
const FLAG: bool;
162+
fn foo () {}
163+
}
164+
struct Foo;
165+
impl Marker for Foo {
166+
const FLAG: bool = false;
167+
}
168+
"#,
169+
)
170+
}
171+
172+
#[test]
173+
fn quickfix_for_assoc_type() {
174+
check_fix(
175+
r#"
176+
trait Marker {
177+
}
178+
struct Foo;
179+
impl Marker for Foo {
180+
type T = i32;$0
181+
}
182+
"#,
183+
r#"
184+
trait Marker {
185+
type T;
186+
}
187+
struct Foo;
188+
impl Marker for Foo {
189+
type T = i32;
190+
}
191+
"#,
192+
)
193+
}
194+
195+
#[test]
196+
fn quickfix_dont_work() {
197+
check_no_fix(
198+
r#"
199+
//- /dep.rs crate:dep
200+
trait Marker {
201+
}
202+
//- /main.rs crate:main deps:dep
203+
struct Foo;
204+
impl dep::Marker for Foo {
205+
type T = i32;$0
206+
}
207+
"#,
208+
)
209+
}
119210

120211
#[test]
121212
fn trait_with_default_value() {
@@ -129,12 +220,12 @@ trait Marker {
129220
struct Foo;
130221
impl Marker for Foo {
131222
type T = i32;
132-
//^^^^^^^^^^^^^ error: `type T` is not a member of trait `Marker`
223+
//^^^^^^^^^^^^^ 💡 error: `type T` is not a member of trait `Marker`
133224
134225
const FLAG: bool = true;
135226
136227
fn bar() {}
137-
//^^^^^^^^^^^ error: `fn bar` is not a member of trait `Marker`
228+
//^^^^^^^^^^^ 💡 error: `fn bar` is not a member of trait `Marker`
138229
139230
fn boo() {}
140231
}

0 commit comments

Comments
 (0)