diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-15 12:34:37 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-15 12:34:37 +0000 |
commit | 435d46b1835eb29ffdefc6dacd609838a5c1035a (patch) | |
tree | fa29a644734904fca5e1ba1bfca6b7fd93ae1c8b /crates | |
parent | a9d19200f2a7334404f69849cae5a4723db965e0 (diff) | |
parent | c582e52a1be88d4d0465f3eb396640d0b619dedf (diff) |
Merge #6888
6888: Use standard test style r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/assists/src/handlers/reorder_fields.rs | 129 |
1 files changed, 67 insertions, 62 deletions
diff --git a/crates/assists/src/handlers/reorder_fields.rs b/crates/assists/src/handlers/reorder_fields.rs index 7c0f0f44e..fe5574242 100644 --- a/crates/assists/src/handlers/reorder_fields.rs +++ b/crates/assists/src/handlers/reorder_fields.rs | |||
@@ -4,6 +4,7 @@ use rustc_hash::FxHashMap; | |||
4 | use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; | 4 | use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; |
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; | 6 | use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; |
7 | use test_utils::mark; | ||
7 | 8 | ||
8 | use crate::{AssistContext, AssistId, AssistKind, Assists}; | 9 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
9 | 10 | ||
@@ -38,6 +39,7 @@ fn reorder<R: AstNode>(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | |||
38 | }); | 39 | }); |
39 | 40 | ||
40 | if sorted_fields == fields { | 41 | if sorted_fields == fields { |
42 | mark::hit!(reorder_sorted_fields); | ||
41 | return None; | 43 | return None; |
42 | } | 44 | } |
43 | 45 | ||
@@ -107,22 +109,25 @@ fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashM | |||
107 | 109 | ||
108 | #[cfg(test)] | 110 | #[cfg(test)] |
109 | mod tests { | 111 | mod tests { |
112 | use test_utils::mark; | ||
113 | |||
110 | use crate::tests::{check_assist, check_assist_not_applicable}; | 114 | use crate::tests::{check_assist, check_assist_not_applicable}; |
111 | 115 | ||
112 | use super::*; | 116 | use super::*; |
113 | 117 | ||
114 | #[test] | 118 | #[test] |
115 | fn not_applicable_if_sorted() { | 119 | fn reorder_sorted_fields() { |
120 | mark::check!(reorder_sorted_fields); | ||
116 | check_assist_not_applicable( | 121 | check_assist_not_applicable( |
117 | reorder_fields, | 122 | reorder_fields, |
118 | r#" | 123 | r#" |
119 | struct Foo { | 124 | struct Foo { |
120 | foo: i32, | 125 | foo: i32, |
121 | bar: i32, | 126 | bar: i32, |
122 | } | 127 | } |
123 | 128 | ||
124 | const test: Foo = <|>Foo { foo: 0, bar: 0 }; | 129 | const test: Foo = <|>Foo { foo: 0, bar: 0 }; |
125 | "#, | 130 | "#, |
126 | ) | 131 | ) |
127 | } | 132 | } |
128 | 133 | ||
@@ -131,9 +136,9 @@ mod tests { | |||
131 | check_assist_not_applicable( | 136 | check_assist_not_applicable( |
132 | reorder_fields, | 137 | reorder_fields, |
133 | r#" | 138 | r#" |
134 | struct Foo {}; | 139 | struct Foo {}; |
135 | const test: Foo = <|>Foo {} | 140 | const test: Foo = <|>Foo {} |
136 | "#, | 141 | "#, |
137 | ) | 142 | ) |
138 | } | 143 | } |
139 | 144 | ||
@@ -142,13 +147,13 @@ mod tests { | |||
142 | check_assist( | 147 | check_assist( |
143 | reorder_fields, | 148 | reorder_fields, |
144 | r#" | 149 | r#" |
145 | struct Foo {foo: i32, bar: i32}; | 150 | struct Foo {foo: i32, bar: i32}; |
146 | const test: Foo = <|>Foo {bar: 0, foo: 1} | 151 | const test: Foo = <|>Foo {bar: 0, foo: 1} |
147 | "#, | 152 | "#, |
148 | r#" | 153 | r#" |
149 | struct Foo {foo: i32, bar: i32}; | 154 | struct Foo {foo: i32, bar: i32}; |
150 | const test: Foo = Foo {foo: 1, bar: 0} | 155 | const test: Foo = Foo {foo: 1, bar: 0} |
151 | "#, | 156 | "#, |
152 | ) | 157 | ) |
153 | } | 158 | } |
154 | 159 | ||
@@ -157,25 +162,25 @@ mod tests { | |||
157 | check_assist( | 162 | check_assist( |
158 | reorder_fields, | 163 | reorder_fields, |
159 | r#" | 164 | r#" |
160 | struct Foo { foo: i64, bar: i64, baz: i64 } | 165 | struct Foo { foo: i64, bar: i64, baz: i64 } |
161 | 166 | ||
162 | fn f(f: Foo) -> { | 167 | fn f(f: Foo) -> { |
163 | match f { | 168 | match f { |
164 | <|>Foo { baz: 0, ref mut bar, .. } => (), | 169 | <|>Foo { baz: 0, ref mut bar, .. } => (), |
165 | _ => () | 170 | _ => () |
166 | } | 171 | } |
167 | } | 172 | } |
168 | "#, | 173 | "#, |
169 | r#" | 174 | r#" |
170 | struct Foo { foo: i64, bar: i64, baz: i64 } | 175 | struct Foo { foo: i64, bar: i64, baz: i64 } |
171 | 176 | ||
172 | fn f(f: Foo) -> { | 177 | fn f(f: Foo) -> { |
173 | match f { | 178 | match f { |
174 | Foo { ref mut bar, baz: 0, .. } => (), | 179 | Foo { ref mut bar, baz: 0, .. } => (), |
175 | _ => () | 180 | _ => () |
176 | } | 181 | } |
177 | } | 182 | } |
178 | "#, | 183 | "#, |
179 | ) | 184 | ) |
180 | } | 185 | } |
181 | 186 | ||
@@ -184,39 +189,39 @@ mod tests { | |||
184 | check_assist( | 189 | check_assist( |
185 | reorder_fields, | 190 | reorder_fields, |
186 | r#" | 191 | r#" |
187 | struct Foo { | 192 | struct Foo { |
188 | foo: String, | 193 | foo: String, |
189 | bar: String, | 194 | bar: String, |
190 | } | 195 | } |
191 | 196 | ||
192 | impl Foo { | 197 | impl Foo { |
193 | fn new() -> Foo { | 198 | fn new() -> Foo { |
194 | let foo = String::new(); | 199 | let foo = String::new(); |
195 | <|>Foo { | 200 | <|>Foo { |
196 | bar: foo.clone(), | 201 | bar: foo.clone(), |
197 | extra: "Extra field", | 202 | extra: "Extra field", |
198 | foo, | 203 | foo, |
199 | } | 204 | } |
200 | } | 205 | } |
201 | } | 206 | } |
202 | "#, | 207 | "#, |
203 | r#" | 208 | r#" |
204 | struct Foo { | 209 | struct Foo { |
205 | foo: String, | 210 | foo: String, |
206 | bar: String, | 211 | bar: String, |
207 | } | 212 | } |
208 | 213 | ||
209 | impl Foo { | 214 | impl Foo { |
210 | fn new() -> Foo { | 215 | fn new() -> Foo { |
211 | let foo = String::new(); | 216 | let foo = String::new(); |
212 | Foo { | 217 | Foo { |
213 | foo, | 218 | foo, |
214 | bar: foo.clone(), | 219 | bar: foo.clone(), |
215 | extra: "Extra field", | 220 | extra: "Extra field", |
216 | } | 221 | } |
217 | } | 222 | } |
218 | } | 223 | } |
219 | "#, | 224 | "#, |
220 | ) | 225 | ) |
221 | } | 226 | } |
222 | } | 227 | } |