diff options
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/flip_trait_bound.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/crates/ra_assists/src/assists/flip_trait_bound.rs b/crates/ra_assists/src/assists/flip_trait_bound.rs index a2c954ec5..203092d03 100644 --- a/crates/ra_assists/src/assists/flip_trait_bound.rs +++ b/crates/ra_assists/src/assists/flip_trait_bound.rs | |||
@@ -30,3 +30,79 @@ pub(crate) fn flip_trait_bound(mut ctx: AssistCtx<impl HirDatabase>) -> Option<A | |||
30 | 30 | ||
31 | ctx.build() | 31 | ctx.build() |
32 | } | 32 | } |
33 | |||
34 | #[cfg(test)] | ||
35 | mod tests { | ||
36 | use super::*; | ||
37 | |||
38 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | ||
39 | |||
40 | #[test] | ||
41 | fn flip_trait_bound_assist_available() { | ||
42 | check_assist_target(flip_trait_bound, "struct S<T> where T: A <|>+ B + C { }", "+") | ||
43 | } | ||
44 | |||
45 | #[test] | ||
46 | fn flip_trait_bound_not_applicable_for_single_trait_bound() { | ||
47 | check_assist_not_applicable(flip_trait_bound, "struct S<T> where T: <|>A { }") | ||
48 | } | ||
49 | |||
50 | #[test] | ||
51 | fn flip_trait_bound_works_for_struct() { | ||
52 | check_assist( | ||
53 | flip_trait_bound, | ||
54 | "struct S<T> where T: A <|>+ B { }", | ||
55 | "struct S<T> where T: B <|>+ A { }", | ||
56 | ) | ||
57 | } | ||
58 | |||
59 | #[test] | ||
60 | fn flip_trait_bound_works_for_trait_impl() { | ||
61 | check_assist( | ||
62 | flip_trait_bound, | ||
63 | "impl X for S<T> where T: A +<|> B { }", | ||
64 | "impl X for S<T> where T: B +<|> A { }", | ||
65 | ) | ||
66 | } | ||
67 | |||
68 | #[test] | ||
69 | fn flip_trait_bound_works_for_fn() { | ||
70 | check_assist(flip_trait_bound, "fn f<T: A <|>+ B>(t: T) { }", "fn f<T: B <|>+ A>(t: T) { }") | ||
71 | } | ||
72 | |||
73 | #[test] | ||
74 | fn flip_trait_bound_works_for_fn_where_clause() { | ||
75 | check_assist( | ||
76 | flip_trait_bound, | ||
77 | "fn f<T>(t: T) where T: A +<|> B { }", | ||
78 | "fn f<T>(t: T) where T: B +<|> A { }", | ||
79 | ) | ||
80 | } | ||
81 | |||
82 | #[test] | ||
83 | fn flip_trait_bound_works_for_lifetime() { | ||
84 | check_assist( | ||
85 | flip_trait_bound, | ||
86 | "fn f<T>(t: T) where T: A <|>+ 'static { }", | ||
87 | "fn f<T>(t: T) where T: 'static <|>+ A { }", | ||
88 | ) | ||
89 | } | ||
90 | |||
91 | #[test] | ||
92 | fn flip_trait_bound_works_for_complex_bounds() { | ||
93 | check_assist( | ||
94 | flip_trait_bound, | ||
95 | "struct S<T> where T: A<T> <|>+ b_mod::B<T> + C<T> { }", | ||
96 | "struct S<T> where T: b_mod::B<T> <|>+ A<T> + C<T> { }", | ||
97 | ) | ||
98 | } | ||
99 | |||
100 | #[test] | ||
101 | fn flip_trait_bound_works_for_long_bounds() { | ||
102 | check_assist( | ||
103 | flip_trait_bound, | ||
104 | "struct S<T> where T: A + B + C + D + E + F +<|> G + H + I + J { }", | ||
105 | "struct S<T> where T: A + B + C + D + E + G +<|> F + H + I + J { }", | ||
106 | ) | ||
107 | } | ||
108 | } | ||