diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-03 11:57:36 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-03 11:57:36 +0100 |
commit | 57576ac420989070e695bac195d516a410191ad9 (patch) | |
tree | 007c62c899cedd397501d1c2d477c61ac071c84c /crates/ra_ide/src/completion | |
parent | 81bb3d9c1a1cfd1e94a3c43013eb7f63cf54f8c7 (diff) | |
parent | e2b04621f9213b14b57df366138f38252735ffad (diff) |
Merge #5200
5200: Refactor keyword completion tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/complete_keyword.rs | 404 |
1 files changed, 198 insertions, 206 deletions
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index e599cc3d1..c3c6eda33 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs | |||
@@ -174,289 +174,281 @@ fn complete_return( | |||
174 | 174 | ||
175 | #[cfg(test)] | 175 | #[cfg(test)] |
176 | mod tests { | 176 | mod tests { |
177 | use expect::{expect, Expect}; | ||
178 | |||
177 | use crate::completion::{test_utils::completion_list, CompletionKind}; | 179 | use crate::completion::{test_utils::completion_list, CompletionKind}; |
178 | use insta::assert_snapshot; | ||
179 | 180 | ||
180 | fn get_keyword_completions(code: &str) -> String { | 181 | fn check(ra_fixture: &str, expect: Expect) { |
181 | completion_list(code, CompletionKind::Keyword) | 182 | let actual = completion_list(ra_fixture, CompletionKind::Keyword); |
183 | expect.assert_eq(&actual) | ||
182 | } | 184 | } |
183 | 185 | ||
184 | #[test] | 186 | #[test] |
185 | fn test_keywords_in_use_stmt() { | 187 | fn test_keywords_in_use_stmt() { |
186 | assert_snapshot!( | 188 | check( |
187 | get_keyword_completions(r"use <|>"), | 189 | r"use <|>", |
188 | @r###" | 190 | expect![[r#" |
189 | kw crate:: | 191 | kw crate:: |
190 | kw self | 192 | kw self |
191 | kw super:: | 193 | kw super:: |
192 | "### | 194 | "#]], |
193 | ); | 195 | ); |
194 | 196 | ||
195 | assert_snapshot!( | 197 | check( |
196 | get_keyword_completions(r"use a::<|>"), | 198 | r"use a::<|>", |
197 | @r###" | 199 | expect![[r#" |
198 | kw self | 200 | kw self |
199 | kw super:: | 201 | kw super:: |
200 | "### | 202 | "#]], |
201 | ); | 203 | ); |
202 | 204 | ||
203 | assert_snapshot!( | 205 | check( |
204 | get_keyword_completions(r"use a::{b, <|>}"), | 206 | r"use a::{b, <|>}", |
205 | @r###" | 207 | expect![[r#" |
206 | kw self | 208 | kw self |
207 | kw super:: | 209 | kw super:: |
208 | "### | 210 | "#]], |
209 | ); | 211 | ); |
210 | } | 212 | } |
211 | 213 | ||
212 | #[test] | 214 | #[test] |
213 | fn test_keywords_at_source_file_level() { | 215 | fn test_keywords_at_source_file_level() { |
214 | assert_snapshot!( | 216 | check( |
215 | get_keyword_completions(r"m<|>"), | 217 | r"m<|>", |
216 | @r###" | 218 | expect![[r#" |
217 | kw const | 219 | kw const |
218 | kw enum | 220 | kw enum |
219 | kw extern | 221 | kw extern |
220 | kw fn | 222 | kw fn |
221 | kw impl | 223 | kw impl |
222 | kw mod | 224 | kw mod |
223 | kw pub | 225 | kw pub |
224 | kw static | 226 | kw static |
225 | kw struct | 227 | kw struct |
226 | kw trait | 228 | kw trait |
227 | kw type | 229 | kw type |
228 | kw union | 230 | kw union |
229 | kw unsafe | 231 | kw unsafe |
230 | kw use | 232 | kw use |
231 | "### | 233 | "#]], |
232 | ); | 234 | ); |
233 | } | 235 | } |
234 | 236 | ||
235 | #[test] | 237 | #[test] |
236 | fn test_keywords_in_function() { | 238 | fn test_keywords_in_function() { |
237 | assert_snapshot!( | 239 | check( |
238 | get_keyword_completions(r"fn quux() { <|> }"), | 240 | r"fn quux() { <|> }", |
239 | @r###" | 241 | expect![[r#" |
240 | kw const | 242 | kw const |
241 | kw extern | 243 | kw extern |
242 | kw fn | 244 | kw fn |
243 | kw if | 245 | kw if |
244 | kw if let | 246 | kw if let |
245 | kw impl | 247 | kw impl |
246 | kw let | 248 | kw let |
247 | kw loop | 249 | kw loop |
248 | kw match | 250 | kw match |
249 | kw mod | 251 | kw mod |
250 | kw return | 252 | kw return |
251 | kw static | 253 | kw static |
252 | kw trait | 254 | kw trait |
253 | kw type | 255 | kw type |
254 | kw unsafe | 256 | kw unsafe |
255 | kw use | 257 | kw use |
256 | kw while | 258 | kw while |
257 | "### | 259 | "#]], |
258 | ); | 260 | ); |
259 | } | 261 | } |
260 | 262 | ||
261 | #[test] | 263 | #[test] |
262 | fn test_keywords_inside_block() { | 264 | fn test_keywords_inside_block() { |
263 | assert_snapshot!( | 265 | check( |
264 | get_keyword_completions(r"fn quux() { if true { <|> } }"), | 266 | r"fn quux() { if true { <|> } }", |
265 | @r###" | 267 | expect![[r#" |
266 | kw const | 268 | kw const |
267 | kw extern | 269 | kw extern |
268 | kw fn | 270 | kw fn |
269 | kw if | 271 | kw if |
270 | kw if let | 272 | kw if let |
271 | kw impl | 273 | kw impl |
272 | kw let | 274 | kw let |
273 | kw loop | 275 | kw loop |
274 | kw match | 276 | kw match |
275 | kw mod | 277 | kw mod |
276 | kw return | 278 | kw return |
277 | kw static | 279 | kw static |
278 | kw trait | 280 | kw trait |
279 | kw type | 281 | kw type |
280 | kw unsafe | 282 | kw unsafe |
281 | kw use | 283 | kw use |
282 | kw while | 284 | kw while |
283 | "### | 285 | "#]], |
284 | ); | 286 | ); |
285 | } | 287 | } |
286 | 288 | ||
287 | #[test] | 289 | #[test] |
288 | fn test_keywords_after_if() { | 290 | fn test_keywords_after_if() { |
289 | assert_snapshot!( | 291 | check( |
290 | get_keyword_completions( | 292 | r#"fn quux() { if true { () } <|> }"#, |
291 | r" | 293 | expect![[r#" |
292 | fn quux() { | 294 | kw const |
293 | if true { | 295 | kw else |
294 | () | 296 | kw else if |
295 | } <|> | 297 | kw extern |
296 | } | 298 | kw fn |
297 | ", | 299 | kw if |
298 | ), | 300 | kw if let |
299 | @r###" | 301 | kw impl |
300 | kw const | 302 | kw let |
301 | kw else | 303 | kw loop |
302 | kw else if | 304 | kw match |
303 | kw extern | 305 | kw mod |
304 | kw fn | 306 | kw return |
305 | kw if | 307 | kw static |
306 | kw if let | 308 | kw trait |
307 | kw impl | 309 | kw type |
308 | kw let | 310 | kw unsafe |
309 | kw loop | 311 | kw use |
310 | kw match | 312 | kw while |
311 | kw mod | 313 | "#]], |
312 | kw return | ||
313 | kw static | ||
314 | kw trait | ||
315 | kw type | ||
316 | kw unsafe | ||
317 | kw use | ||
318 | kw while | ||
319 | "### | ||
320 | ); | 314 | ); |
321 | } | 315 | } |
322 | 316 | ||
323 | #[test] | 317 | #[test] |
324 | fn test_keywords_in_match_arm() { | 318 | fn test_keywords_in_match_arm() { |
325 | assert_snapshot!( | 319 | check( |
326 | get_keyword_completions( | 320 | r#" |
327 | r" | 321 | fn quux() -> i32 { |
328 | fn quux() -> i32 { | 322 | match () { |
329 | match () { | 323 | () => <|> |
330 | () => <|> | 324 | } |
331 | } | 325 | } |
332 | } | 326 | "#, |
333 | ", | 327 | expect![[r#" |
334 | ), | 328 | kw if |
335 | @r###" | 329 | kw if let |
336 | kw if | 330 | kw loop |
337 | kw if let | 331 | kw match |
338 | kw loop | 332 | kw return |
339 | kw match | 333 | kw unsafe |
340 | kw return | 334 | "#]], |
341 | kw unsafe | ||
342 | "### | ||
343 | ); | 335 | ); |
344 | } | 336 | } |
345 | 337 | ||
346 | #[test] | 338 | #[test] |
347 | fn test_keywords_in_trait_def() { | 339 | fn test_keywords_in_trait_def() { |
348 | assert_snapshot!( | 340 | check( |
349 | get_keyword_completions(r"trait My { <|> }"), | 341 | r"trait My { <|> }", |
350 | @r###" | 342 | expect![[r#" |
351 | kw const | 343 | kw const |
352 | kw fn | 344 | kw fn |
353 | kw type | 345 | kw type |
354 | kw unsafe | 346 | kw unsafe |
355 | "### | 347 | "#]], |
356 | ); | 348 | ); |
357 | } | 349 | } |
358 | 350 | ||
359 | #[test] | 351 | #[test] |
360 | fn test_keywords_in_impl_def() { | 352 | fn test_keywords_in_impl_def() { |
361 | assert_snapshot!( | 353 | check( |
362 | get_keyword_completions(r"impl My { <|> }"), | 354 | r"impl My { <|> }", |
363 | @r###" | 355 | expect![[r#" |
364 | kw const | 356 | kw const |
365 | kw fn | 357 | kw fn |
366 | kw pub | 358 | kw pub |
367 | kw type | 359 | kw type |
368 | kw unsafe | 360 | kw unsafe |
369 | "### | 361 | "#]], |
370 | ); | 362 | ); |
371 | } | 363 | } |
372 | 364 | ||
373 | #[test] | 365 | #[test] |
374 | fn test_keywords_in_loop() { | 366 | fn test_keywords_in_loop() { |
375 | assert_snapshot!( | 367 | check( |
376 | get_keyword_completions(r"fn my() { loop { <|> } }"), | 368 | r"fn my() { loop { <|> } }", |
377 | @r###" | 369 | expect![[r#" |
378 | kw break | 370 | kw break |
379 | kw const | 371 | kw const |
380 | kw continue | 372 | kw continue |
381 | kw extern | 373 | kw extern |
382 | kw fn | 374 | kw fn |
383 | kw if | 375 | kw if |
384 | kw if let | 376 | kw if let |
385 | kw impl | 377 | kw impl |
386 | kw let | 378 | kw let |
387 | kw loop | 379 | kw loop |
388 | kw match | 380 | kw match |
389 | kw mod | 381 | kw mod |
390 | kw return | 382 | kw return |
391 | kw static | 383 | kw static |
392 | kw trait | 384 | kw trait |
393 | kw type | 385 | kw type |
394 | kw unsafe | 386 | kw unsafe |
395 | kw use | 387 | kw use |
396 | kw while | 388 | kw while |
397 | "### | 389 | "#]], |
398 | ); | 390 | ); |
399 | } | 391 | } |
400 | 392 | ||
401 | #[test] | 393 | #[test] |
402 | fn test_keywords_after_unsafe_in_item_list() { | 394 | fn test_keywords_after_unsafe_in_item_list() { |
403 | assert_snapshot!( | 395 | check( |
404 | get_keyword_completions(r"unsafe <|>"), | 396 | r"unsafe <|>", |
405 | @r###" | 397 | expect![[r#" |
406 | kw fn | 398 | kw fn |
407 | kw impl | 399 | kw impl |
408 | kw trait | 400 | kw trait |
409 | "### | 401 | "#]], |
410 | ); | 402 | ); |
411 | } | 403 | } |
412 | 404 | ||
413 | #[test] | 405 | #[test] |
414 | fn test_keywords_after_unsafe_in_block_expr() { | 406 | fn test_keywords_after_unsafe_in_block_expr() { |
415 | assert_snapshot!( | 407 | check( |
416 | get_keyword_completions(r"fn my_fn() { unsafe <|> }"), | 408 | r"fn my_fn() { unsafe <|> }", |
417 | @r###" | 409 | expect![[r#" |
418 | kw fn | 410 | kw fn |
419 | kw impl | 411 | kw impl |
420 | kw trait | 412 | kw trait |
421 | "### | 413 | "#]], |
422 | ); | 414 | ); |
423 | } | 415 | } |
424 | 416 | ||
425 | #[test] | 417 | #[test] |
426 | fn test_mut_in_ref_and_in_fn_parameters_list() { | 418 | fn test_mut_in_ref_and_in_fn_parameters_list() { |
427 | assert_snapshot!( | 419 | check( |
428 | get_keyword_completions(r"fn my_fn(&<|>) {}"), | 420 | r"fn my_fn(&<|>) {}", |
429 | @r###" | 421 | expect![[r#" |
430 | kw mut | 422 | kw mut |
431 | "### | 423 | "#]], |
432 | ); | 424 | ); |
433 | assert_snapshot!( | 425 | check( |
434 | get_keyword_completions(r"fn my_fn(<|>) {}"), | 426 | r"fn my_fn(<|>) {}", |
435 | @r###" | 427 | expect![[r#" |
436 | kw mut | 428 | kw mut |
437 | "### | 429 | "#]], |
438 | ); | 430 | ); |
439 | assert_snapshot!( | 431 | check( |
440 | get_keyword_completions(r"fn my_fn() { let &<|> }"), | 432 | r"fn my_fn() { let &<|> }", |
441 | @r###" | 433 | expect![[r#" |
442 | kw mut | 434 | kw mut |
443 | "### | 435 | "#]], |
444 | ); | 436 | ); |
445 | } | 437 | } |
446 | 438 | ||
447 | #[test] | 439 | #[test] |
448 | fn test_where_keyword() { | 440 | fn test_where_keyword() { |
449 | assert_snapshot!( | 441 | check( |
450 | get_keyword_completions(r"trait A <|>"), | 442 | r"trait A <|>", |
451 | @r###" | 443 | expect![[r#" |
452 | kw where | 444 | kw where |
453 | "### | 445 | "#]], |
454 | ); | 446 | ); |
455 | assert_snapshot!( | 447 | check( |
456 | get_keyword_completions(r"impl A <|>"), | 448 | r"impl A <|>", |
457 | @r###" | 449 | expect![[r#" |
458 | kw where | 450 | kw where |
459 | "### | 451 | "#]], |
460 | ); | 452 | ); |
461 | } | 453 | } |
462 | } | 454 | } |