aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-04 22:22:07 +0100
committerAleksey Kladov <[email protected]>2020-07-04 22:25:33 +0100
commit453167b492872643286dfcb9d540fce6f4b36209 (patch)
tree4fadf535bcb63a7d2777207efb648ff2ac0d384b /crates
parent4cfe0070dda16096c17c992ddb6c2d37b8ff4c39 (diff)
Modernise item completion tests
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs464
1 files changed, 199 insertions, 265 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index 23e42928d..a610fd6d1 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -227,330 +227,264 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
227 227
228#[cfg(test)] 228#[cfg(test)]
229mod tests { 229mod tests {
230 use insta::assert_debug_snapshot; 230 use expect::{expect, Expect};
231 231
232 use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; 232 use crate::completion::{
233 test_utils::{check_edit, completion_list},
234 CompletionKind,
235 };
233 236
234 fn complete(code: &str) -> Vec<CompletionItem> { 237 fn check(ra_fixture: &str, expect: Expect) {
235 do_completion(code, CompletionKind::Magic) 238 let actual = completion_list(ra_fixture, CompletionKind::Magic);
239 expect.assert_eq(&actual)
236 } 240 }
237 241
238 #[test] 242 #[test]
239 fn name_ref_function_type_const() { 243 fn name_ref_function_type_const() {
240 let completions = complete( 244 check(
241 r" 245 r#"
242 trait Test { 246trait Test {
243 type TestType; 247 type TestType;
244 const TEST_CONST: u16; 248 const TEST_CONST: u16;
245 fn test(); 249 fn test();
246 } 250}
247 251struct T;
248 struct T1;
249 252
250 impl Test for T1 { 253impl Test for T {
251 t<|> 254 t<|>
252 } 255}
253 ", 256"#,
257 expect![["
258ct const TEST_CONST: u16 = \n\
259fn fn test()
260ta type TestType = \n\
261 "]],
254 ); 262 );
255 assert_debug_snapshot!(completions, @r###"
256 [
257 CompletionItem {
258 label: "const TEST_CONST: u16 = ",
259 source_range: 112..113,
260 delete: 112..113,
261 insert: "const TEST_CONST: u16 = ",
262 kind: Const,
263 lookup: "TEST_CONST",
264 },
265 CompletionItem {
266 label: "fn test()",
267 source_range: 112..113,
268 delete: 112..113,
269 insert: "fn test() {\n $0\n}",
270 kind: Function,
271 lookup: "test",
272 },
273 CompletionItem {
274 label: "type TestType = ",
275 source_range: 112..113,
276 delete: 112..113,
277 insert: "type TestType = ",
278 kind: TypeAlias,
279 lookup: "TestType",
280 },
281 ]
282 "###);
283 } 263 }
284 264
285 #[test] 265 #[test]
286 fn no_nested_fn_completions() { 266 fn no_nested_fn_completions() {
287 let completions = complete( 267 check(
288 r" 268 r"
289 trait Test { 269trait Test {
290 fn test(); 270 fn test();
291 fn test2(); 271 fn test2();
292 } 272}
293 273struct T;
294 struct T1;
295 274
296 impl Test for T1 { 275impl Test for T {
297 fn test() { 276 fn test() {
298 t<|> 277 t<|>
299 } 278 }
300 } 279}
301 ", 280",
281 expect![[""]],
302 ); 282 );
303 assert_debug_snapshot!(completions, @r###"[]"###);
304 } 283 }
305 284
306 #[test] 285 #[test]
307 fn name_ref_single_function() { 286 fn name_ref_single_function() {
308 let completions = complete( 287 check_edit(
309 r" 288 "test",
310 trait Test { 289 r#"
311 fn test(); 290trait Test {
312 } 291 fn test();
292}
293struct T;
313 294
314 struct T1; 295impl Test for T {
296 t<|>
297}
298"#,
299 r#"
300trait Test {
301 fn test();
302}
303struct T;
315 304
316 impl Test for T1 { 305impl Test for T {
317 t<|> 306 fn test() {
318 } 307 $0
319 ", 308}
309}
310"#,
320 ); 311 );
321 assert_debug_snapshot!(completions, @r###"
322 [
323 CompletionItem {
324 label: "fn test()",
325 source_range: 66..67,
326 delete: 66..67,
327 insert: "fn test() {\n $0\n}",
328 kind: Function,
329 lookup: "test",
330 },
331 ]
332 "###);
333 } 312 }
334 313
335 #[test] 314 #[test]
336 fn single_function() { 315 fn single_function() {
337 let completions = complete( 316 check_edit(
338 r" 317 "test",
339 trait Test { 318 r#"
340 fn foo(); 319trait Test {
341 } 320 fn test();
321}
322struct T;
342 323
343 struct T1; 324impl Test for T {
325 fn t<|>
326}
327"#,
328 r#"
329trait Test {
330 fn test();
331}
332struct T;
344 333
345 impl Test for T1 { 334impl Test for T {
346 fn f<|> 335 fn test() {
347 } 336 $0
348 ", 337}
338}
339"#,
349 ); 340 );
350 assert_debug_snapshot!(completions, @r###"
351 [
352 CompletionItem {
353 label: "fn foo()",
354 source_range: 68..69,
355 delete: 65..69,
356 insert: "fn foo() {\n $0\n}",
357 kind: Function,
358 lookup: "foo",
359 },
360 ]
361 "###);
362 } 341 }
363 342
364 #[test] 343 #[test]
365 fn hide_implemented_fn() { 344 fn hide_implemented_fn() {
366 let completions = complete( 345 check(
367 r" 346 r#"
368 trait Test { 347trait Test {
369 fn foo(); 348 fn foo();
370 fn foo_bar(); 349 fn foo_bar();
371 } 350}
372 351struct T;
373 struct T1;
374
375 impl Test for T1 {
376 fn foo() {}
377
378 fn f<|>
379 }
380 ",
381 );
382 assert_debug_snapshot!(completions, @r###"
383 [
384 CompletionItem {
385 label: "fn foo_bar()",
386 source_range: 103..104,
387 delete: 100..104,
388 insert: "fn foo_bar() {\n $0\n}",
389 kind: Function,
390 lookup: "foo_bar",
391 },
392 ]
393 "###);
394 }
395
396 #[test]
397 fn completes_only_on_top_level() {
398 let completions = complete(
399 r"
400 trait Test {
401 fn foo();
402
403 fn foo_bar();
404 }
405
406 struct T1;
407 352
408 impl Test for T1 { 353impl Test for T {
409 fn foo() { 354 fn foo() {}
410 <|> 355 fn f<|>
411 } 356}
412 } 357"#,
413 ", 358 expect![[r#"
359 fn fn foo_bar()
360 "#]],
414 ); 361 );
415 assert_debug_snapshot!(completions, @r###"[]"###);
416 } 362 }
417 363
418 #[test] 364 #[test]
419 fn generic_fn() { 365 fn generic_fn() {
420 let completions = complete( 366 check_edit(
421 r" 367 "foo",
422 trait Test { 368 r#"
423 fn foo<T>(); 369trait Test {
424 } 370 fn foo<T>();
371}
372struct T;
425 373
426 struct T1; 374impl Test for T {
375 fn f<|>
376}
377"#,
378 r#"
379trait Test {
380 fn foo<T>();
381}
382struct T;
427 383
428 impl Test for T1 { 384impl Test for T {
429 fn f<|> 385 fn foo<T>() {
430 } 386 $0
431 ", 387}
388}
389"#,
432 ); 390 );
433 assert_debug_snapshot!(completions, @r###" 391 check_edit(
434 [ 392 "foo",
435 CompletionItem { 393 r#"
436 label: "fn foo()", 394trait Test {
437 source_range: 71..72, 395 fn foo<T>() where T: Into<String>;
438 delete: 68..72, 396}
439 insert: "fn foo<T>() {\n $0\n}", 397struct T;
440 kind: Function,
441 lookup: "foo",
442 },
443 ]
444 "###);
445 }
446
447 #[test]
448 fn generic_constrait_fn() {
449 let completions = complete(
450 r"
451 trait Test {
452 fn foo<T>() where T: Into<String>;
453 }
454 398
455 struct T1; 399impl Test for T {
400 fn f<|>
401}
402"#,
403 r#"
404trait Test {
405 fn foo<T>() where T: Into<String>;
406}
407struct T;
456 408
457 impl Test for T1 { 409impl Test for T {
458 fn f<|> 410 fn foo<T>()
459 } 411where T: Into<String> {
460 ", 412 $0
413}
414}
415"#,
461 ); 416 );
462 assert_debug_snapshot!(completions, @r###"
463 [
464 CompletionItem {
465 label: "fn foo()",
466 source_range: 93..94,
467 delete: 90..94,
468 insert: "fn foo<T>()\nwhere T: Into<String> {\n $0\n}",
469 kind: Function,
470 lookup: "foo",
471 },
472 ]
473 "###);
474 } 417 }
475 418
476 #[test] 419 #[test]
477 fn associated_type() { 420 fn associated_type() {
478 let completions = complete( 421 check_edit(
479 r" 422 "SomeType",
480 trait Test { 423 r#"
481 type SomeType; 424trait Test {
482 } 425 type SomeType;
426}
483 427
484 impl Test for () { 428impl Test for () {
485 type S<|> 429 type S<|>
486 } 430}
487 ", 431"#,
432 "
433trait Test {
434 type SomeType;
435}
436
437impl Test for () {
438 type SomeType = \n\
439}
440",
488 ); 441 );
489 assert_debug_snapshot!(completions, @r###"
490 [
491 CompletionItem {
492 label: "type SomeType = ",
493 source_range: 63..64,
494 delete: 58..64,
495 insert: "type SomeType = ",
496 kind: TypeAlias,
497 lookup: "SomeType",
498 },
499 ]
500 "###);
501 } 442 }
502 443
503 #[test] 444 #[test]
504 fn associated_const() { 445 fn associated_const() {
505 let completions = complete( 446 check_edit(
506 r" 447 "SOME_CONST",
507 trait Test { 448 r#"
508 const SOME_CONST: u16; 449trait Test {
509 } 450 const SOME_CONST: u16;
451}
510 452
511 impl Test for () { 453impl Test for () {
512 const S<|> 454 const S<|>
513 } 455}
514 ", 456"#,
457 "
458trait Test {
459 const SOME_CONST: u16;
460}
461
462impl Test for () {
463 const SOME_CONST: u16 = \n\
464}
465",
515 ); 466 );
516 assert_debug_snapshot!(completions, @r###"
517 [
518 CompletionItem {
519 label: "const SOME_CONST: u16 = ",
520 source_range: 72..73,
521 delete: 66..73,
522 insert: "const SOME_CONST: u16 = ",
523 kind: Const,
524 lookup: "SOME_CONST",
525 },
526 ]
527 "###);
528 }
529 467
530 #[test] 468 check_edit(
531 fn associated_const_with_default() { 469 "SOME_CONST",
532 let completions = complete( 470 r#"
533 r" 471trait Test {
534 trait Test { 472 const SOME_CONST: u16 = 92;
535 const SOME_CONST: u16 = 42; 473}
536 }
537 474
538 impl Test for () { 475impl Test for () {
539 const S<|> 476 const S<|>
540 } 477}
541 ", 478"#,
479 "
480trait Test {
481 const SOME_CONST: u16 = 92;
482}
483
484impl Test for () {
485 const SOME_CONST: u16 = \n\
486}
487",
542 ); 488 );
543 assert_debug_snapshot!(completions, @r###"
544 [
545 CompletionItem {
546 label: "const SOME_CONST: u16 = ",
547 source_range: 77..78,
548 delete: 71..78,
549 insert: "const SOME_CONST: u16 = ",
550 kind: Const,
551 lookup: "SOME_CONST",
552 },
553 ]
554 "###);
555 } 489 }
556} 490}