@@ -4,6 +4,7 @@ use rustc_hash::FxHashMap;
4
4
use hir:: { Adt , ModuleDef , PathResolution , Semantics , Struct } ;
5
5
use ide_db:: RootDatabase ;
6
6
use syntax:: { algo, ast, match_ast, AstNode , SyntaxKind , SyntaxKind :: * , SyntaxNode } ;
7
+ use test_utils:: mark;
7
8
8
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
41
if sorted_fields == fields {
42
+ mark:: hit!( reorder_sorted_fields) ;
41
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
110
#[ cfg( test) ]
109
111
mod tests {
112
+ use test_utils:: mark;
113
+
110
114
use crate :: tests:: { check_assist, check_assist_not_applicable} ;
111
115
112
116
use super :: * ;
113
117
114
118
#[ test]
115
- fn not_applicable_if_sorted ( ) {
119
+ fn reorder_sorted_fields ( ) {
120
+ mark:: check!( reorder_sorted_fields) ;
116
121
check_assist_not_applicable (
117
122
reorder_fields,
118
123
r#"
119
- struct Foo {
120
- foo: i32,
121
- bar: i32,
122
- }
124
+ struct Foo {
125
+ foo: i32,
126
+ bar: i32,
127
+ }
123
128
124
- const test: Foo = <|>Foo { foo: 0, bar: 0 };
125
- "#,
129
+ const test: Foo = <|>Foo { foo: 0, bar: 0 };
130
+ "# ,
126
131
)
127
132
}
128
133
@@ -131,9 +136,9 @@ mod tests {
131
136
check_assist_not_applicable (
132
137
reorder_fields,
133
138
r#"
134
- struct Foo {};
135
- const test: Foo = <|>Foo {}
136
- "#,
139
+ struct Foo {};
140
+ const test: Foo = <|>Foo {}
141
+ "# ,
137
142
)
138
143
}
139
144
@@ -142,13 +147,13 @@ mod tests {
142
147
check_assist (
143
148
reorder_fields,
144
149
r#"
145
- struct Foo {foo: i32, bar: i32};
146
- const test: Foo = <|>Foo {bar: 0, foo: 1}
147
- "#,
150
+ struct Foo {foo: i32, bar: i32};
151
+ const test: Foo = <|>Foo {bar: 0, foo: 1}
152
+ "# ,
148
153
r#"
149
- struct Foo {foo: i32, bar: i32};
150
- const test: Foo = Foo {foo: 1, bar: 0}
151
- "#,
154
+ struct Foo {foo: i32, bar: i32};
155
+ const test: Foo = Foo {foo: 1, bar: 0}
156
+ "# ,
152
157
)
153
158
}
154
159
@@ -157,25 +162,25 @@ mod tests {
157
162
check_assist (
158
163
reorder_fields,
159
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) -> {
163
- match f {
164
- <|>Foo { baz: 0, ref mut bar, .. } => (),
165
- _ => ()
166
- }
167
- }
168
- "#,
167
+ fn f(f: Foo) -> {
168
+ match f {
169
+ <|>Foo { baz: 0, ref mut bar, .. } => (),
170
+ _ => ()
171
+ }
172
+ }
173
+ "# ,
169
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) -> {
173
- match f {
174
- Foo { ref mut bar, baz: 0, .. } => (),
175
- _ => ()
176
- }
177
- }
178
- "#,
177
+ fn f(f: Foo) -> {
178
+ match f {
179
+ Foo { ref mut bar, baz: 0, .. } => (),
180
+ _ => ()
181
+ }
182
+ }
183
+ "# ,
179
184
)
180
185
}
181
186
@@ -184,39 +189,39 @@ mod tests {
184
189
check_assist (
185
190
reorder_fields,
186
191
r#"
187
- struct Foo {
188
- foo: String,
189
- bar: String,
190
- }
192
+ struct Foo {
193
+ foo: String,
194
+ bar: String,
195
+ }
191
196
192
- impl Foo {
193
- fn new() -> Foo {
194
- let foo = String::new();
195
- <|>Foo {
196
- bar: foo.clone(),
197
- extra: "Extra field",
198
- foo,
199
- }
200
- }
201
- }
202
- "#,
197
+ impl Foo {
198
+ fn new() -> Foo {
199
+ let foo = String::new();
200
+ <|>Foo {
201
+ bar: foo.clone(),
202
+ extra: "Extra field",
203
+ foo,
204
+ }
205
+ }
206
+ }
207
+ "# ,
203
208
r#"
204
- struct Foo {
205
- foo: String,
206
- bar: String,
207
- }
209
+ struct Foo {
210
+ foo: String,
211
+ bar: String,
212
+ }
208
213
209
- impl Foo {
210
- fn new() -> Foo {
211
- let foo = String::new();
212
- Foo {
213
- foo,
214
- bar: foo.clone(),
215
- extra: "Extra field",
216
- }
217
- }
218
- }
219
- "#,
214
+ impl Foo {
215
+ fn new() -> Foo {
216
+ let foo = String::new();
217
+ Foo {
218
+ foo,
219
+ bar: foo.clone(),
220
+ extra: "Extra field",
221
+ }
222
+ }
223
+ }
224
+ "# ,
220
225
)
221
226
}
222
227
}
0 commit comments