aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-05-27 23:54:52 +0100
committerLukas Wirth <[email protected]>2021-05-28 00:02:41 +0100
commit0724bd0f21e5f7294ee656a89597de9e6df65d29 (patch)
tree225cd1db98c12a11b90c9c3d9e0a5b99eb295cc8 /crates/ide_completion
parent594270be49fbd6e7aee9a36afab02920fd771706 (diff)
Add attribute completion tests
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/attribute.rs407
1 files changed, 399 insertions, 8 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs
index 246a3270a..79a9c6d87 100644
--- a/crates/ide_completion/src/completions/attribute.rs
+++ b/crates/ide_completion/src/completions/attribute.rs
@@ -19,10 +19,6 @@ mod lint;
19pub(crate) use self::lint::LintCompletion; 19pub(crate) use self::lint::LintCompletion;
20 20
21pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 21pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
22 if ctx.mod_declaration_under_caret.is_some() {
23 return None;
24 }
25
26 let attribute = ctx.attribute_under_caret.as_ref()?; 22 let attribute = ctx.attribute_under_caret.as_ref()?;
27 match (attribute.path().and_then(|p| p.as_single_name_ref()), attribute.token_tree()) { 23 match (attribute.path().and_then(|p| p.as_single_name_ref()), attribute.token_tree()) {
28 (Some(path), Some(token_tree)) => match path.text().as_str() { 24 (Some(path), Some(token_tree)) => match path.text().as_str() {
@@ -323,12 +319,280 @@ mod tests {
323 } 319 }
324 320
325 #[test] 321 #[test]
322 fn complete_attribute_on_source_file() {
323 check(
324 r#"#![$0]"#,
325 expect![[r#"
326 at allow(…)
327 at cfg(…)
328 at cfg_attr(…)
329 at deny(…)
330 at forbid(…)
331 at warn(…)
332 at deprecated
333 at doc = "…"
334 at doc(hidden)
335 at doc(alias = "…")
336 at must_use
337 at no_mangle
338 at crate_name = ""
339 at feature(…)
340 at no_implicit_prelude
341 at no_main
342 at no_std
343 at recursion_limit = …
344 at type_length_limit = …
345 at windows_subsystem = "…"
346 "#]],
347 );
348 }
349
350 #[test]
351 fn complete_attribute_on_module() {
352 check(
353 r#"#[$0] mod foo;"#,
354 expect![[r#"
355 at allow(…)
356 at cfg(…)
357 at cfg_attr(…)
358 at deny(…)
359 at forbid(…)
360 at warn(…)
361 at deprecated
362 at doc = "…"
363 at doc(hidden)
364 at doc(alias = "…")
365 at must_use
366 at no_mangle
367 at path = "…"
368 "#]],
369 );
370 check(
371 r#"mod foo {#![$0]}"#,
372 expect![[r#"
373 at allow(…)
374 at cfg(…)
375 at cfg_attr(…)
376 at deny(…)
377 at forbid(…)
378 at warn(…)
379 at deprecated
380 at doc = "…"
381 at doc(hidden)
382 at doc(alias = "…")
383 at must_use
384 at no_mangle
385 at no_implicit_prelude
386 "#]],
387 );
388 }
389
390 #[test]
391 fn complete_attribute_on_macro_rules() {
392 check(
393 r#"#[$0] macro_rules! foo {}"#,
394 expect![[r#"
395 at allow(…)
396 at cfg(…)
397 at cfg_attr(…)
398 at deny(…)
399 at forbid(…)
400 at warn(…)
401 at deprecated
402 at doc = "…"
403 at doc(hidden)
404 at doc(alias = "…")
405 at must_use
406 at no_mangle
407 at macro_export
408 at macro_use
409 "#]],
410 );
411 }
412
413 #[test]
414 fn complete_attribute_on_macro_def() {
415 check(
416 r#"#[$0] macro foo {}"#,
417 expect![[r#"
418 at allow(…)
419 at cfg(…)
420 at cfg_attr(…)
421 at deny(…)
422 at forbid(…)
423 at warn(…)
424 at deprecated
425 at doc = "…"
426 at doc(hidden)
427 at doc(alias = "…")
428 at must_use
429 at no_mangle
430 "#]],
431 );
432 }
433
434 #[test]
435 fn complete_attribute_on_extern_crate() {
436 check(
437 r#"#[$0] extern crate foo;"#,
438 expect![[r#"
439 at allow(…)
440 at cfg(…)
441 at cfg_attr(…)
442 at deny(…)
443 at forbid(…)
444 at warn(…)
445 at deprecated
446 at doc = "…"
447 at doc(hidden)
448 at doc(alias = "…")
449 at must_use
450 at no_mangle
451 at macro_use
452 "#]],
453 );
454 }
455
456 #[test]
457 fn complete_attribute_on_use() {
458 check(
459 r#"#[$0] use foo;"#,
460 expect![[r#"
461 at allow(…)
462 at cfg(…)
463 at cfg_attr(…)
464 at deny(…)
465 at forbid(…)
466 at warn(…)
467 at deprecated
468 at doc = "…"
469 at doc(hidden)
470 at doc(alias = "…")
471 at must_use
472 at no_mangle
473 "#]],
474 );
475 }
476
477 #[test]
478 fn complete_attribute_on_type_alias() {
479 check(
480 r#"#[$0] type foo = ();"#,
481 expect![[r#"
482 at allow(…)
483 at cfg(…)
484 at cfg_attr(…)
485 at deny(…)
486 at forbid(…)
487 at warn(…)
488 at deprecated
489 at doc = "…"
490 at doc(hidden)
491 at doc(alias = "…")
492 at must_use
493 at no_mangle
494 "#]],
495 );
496 }
497
498 #[test]
326 fn complete_attribute_on_struct() { 499 fn complete_attribute_on_struct() {
327 check( 500 check(
328 r#" 501 r#"#[$0] struct Foo;"#,
329#[$0] 502 expect![[r#"
330struct Test {} 503 at allow(…)
331 "#, 504 at cfg(…)
505 at cfg_attr(…)
506 at deny(…)
507 at forbid(…)
508 at warn(…)
509 at deprecated
510 at doc = "…"
511 at doc(hidden)
512 at doc(alias = "…")
513 at must_use
514 at no_mangle
515 at derive(…)
516 at repr(…)
517 at non_exhaustive
518 "#]],
519 );
520 }
521
522 #[test]
523 fn complete_attribute_on_enum() {
524 check(
525 r#"#[$0] enum Foo {}"#,
526 expect![[r#"
527 at allow(…)
528 at cfg(…)
529 at cfg_attr(…)
530 at deny(…)
531 at forbid(…)
532 at warn(…)
533 at deprecated
534 at doc = "…"
535 at doc(hidden)
536 at doc(alias = "…")
537 at must_use
538 at no_mangle
539 at derive(…)
540 at repr(…)
541 at non_exhaustive
542 "#]],
543 );
544 }
545
546 #[test]
547 fn complete_attribute_on_const() {
548 check(
549 r#"#[$0] const FOO: () = ();"#,
550 expect![[r#"
551 at allow(…)
552 at cfg(…)
553 at cfg_attr(…)
554 at deny(…)
555 at forbid(…)
556 at warn(…)
557 at deprecated
558 at doc = "…"
559 at doc(hidden)
560 at doc(alias = "…")
561 at must_use
562 at no_mangle
563 "#]],
564 );
565 }
566
567 #[test]
568 fn complete_attribute_on_static() {
569 check(
570 r#"#[$0] static FOO: () = ()"#,
571 expect![[r#"
572 at allow(…)
573 at cfg(…)
574 at cfg_attr(…)
575 at deny(…)
576 at forbid(…)
577 at warn(…)
578 at deprecated
579 at doc = "…"
580 at doc(hidden)
581 at doc(alias = "…")
582 at must_use
583 at no_mangle
584 at export_name = "…"
585 at link_name = "…"
586 at link_section = "…"
587 at used
588 "#]],
589 );
590 }
591
592 #[test]
593 fn complete_attribute_on_trait() {
594 check(
595 r#"#[$0] trait Foo {}"#,
332 expect![[r#" 596 expect![[r#"
333 at allow(…) 597 at allow(…)
334 at cfg(…) 598 at cfg(…)
@@ -337,10 +601,137 @@ struct Test {}
337 at forbid(…) 601 at forbid(…)
338 at warn(…) 602 at warn(…)
339 at deprecated 603 at deprecated
604 at doc = "…"
605 at doc(hidden)
606 at doc(alias = "…")
607 at must_use
608 at no_mangle
340 at must_use 609 at must_use
341 "#]], 610 "#]],
342 ); 611 );
343 } 612 }
613
614 #[test]
615 fn complete_attribute_on_impl() {
616 check(
617 r#"#[$0] impl () {}"#,
618 expect![[r#"
619 at allow(…)
620 at cfg(…)
621 at cfg_attr(…)
622 at deny(…)
623 at forbid(…)
624 at warn(…)
625 at deprecated
626 at doc = "…"
627 at doc(hidden)
628 at doc(alias = "…")
629 at must_use
630 at no_mangle
631 at automatically_derived
632 "#]],
633 );
634 check(
635 r#"impl () {#![$0]}"#,
636 expect![[r#"
637 at allow(…)
638 at cfg(…)
639 at cfg_attr(…)
640 at deny(…)
641 at forbid(…)
642 at warn(…)
643 at deprecated
644 at doc = "…"
645 at doc(hidden)
646 at doc(alias = "…")
647 at must_use
648 at no_mangle
649 "#]],
650 );
651 }
652
653 #[test]
654 fn complete_attribute_on_extern_block() {
655 check(
656 r#"#[$0] extern {}"#,
657 expect![[r#"
658 at allow(…)
659 at cfg(…)
660 at cfg_attr(…)
661 at deny(…)
662 at forbid(…)
663 at warn(…)
664 at deprecated
665 at doc = "…"
666 at doc(hidden)
667 at doc(alias = "…")
668 at must_use
669 at no_mangle
670 at link
671 "#]],
672 );
673 check(
674 r#"extern {#![$0]}"#,
675 expect![[r#"
676 at allow(…)
677 at cfg(…)
678 at cfg_attr(…)
679 at deny(…)
680 at forbid(…)
681 at warn(…)
682 at deprecated
683 at doc = "…"
684 at doc(hidden)
685 at doc(alias = "…")
686 at must_use
687 at no_mangle
688 at link
689 "#]],
690 );
691 }
692
693 #[test]
694 fn complete_attribute_on_variant() {
695 check(
696 r#"enum Foo { #[$0] Bar }"#,
697 expect![[r#"
698 at allow(…)
699 at cfg(…)
700 at cfg_attr(…)
701 at deny(…)
702 at forbid(…)
703 at warn(…)
704 at non_exhaustive
705 "#]],
706 );
707 }
708
709 #[test]
710 fn complete_attribute_on_expr() {
711 check(
712 r#"fn main() { #[$0] foo() }"#,
713 expect![[r#"
714 at allow(…)
715 at cfg(…)
716 at cfg_attr(…)
717 at deny(…)
718 at forbid(…)
719 at warn(…)
720 "#]],
721 );
722 check(
723 r#"fn main() { #[$0] foo(); }"#,
724 expect![[r#"
725 at allow(…)
726 at cfg(…)
727 at cfg_attr(…)
728 at deny(…)
729 at forbid(…)
730 at warn(…)
731 "#]],
732 );
733 }
734
344 #[test] 735 #[test]
345 fn test_attribute_completion_inside_nested_attr() { 736 fn test_attribute_completion_inside_nested_attr() {
346 check(r#"#[cfg($0)]"#, expect![[]]) 737 check(r#"#[cfg($0)]"#, expect![[]])