aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs239
1 files changed, 105 insertions, 134 deletions
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index e94fbce3a..2e52a29a8 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -575,7 +575,7 @@ version = \"0.0.0\"
575} 575}
576 576
577#[test] 577#[test]
578fn resolve_include_concat_env() { 578fn out_dirs_check() {
579 if skip_slow_tests() { 579 if skip_slow_tests() {
580 return; 580 return;
581 } 581 }
@@ -598,11 +598,28 @@ fn main() {
598 r#"pub fn message() -> &'static str { "Hello, World!" }"#, 598 r#"pub fn message() -> &'static str { "Hello, World!" }"#,
599 ) 599 )
600 .unwrap(); 600 .unwrap();
601 println!("cargo:rustc-cfg=atom_cfg");
602 println!("cargo:rustc-cfg=featlike=\"set\"");
601 println!("cargo:rerun-if-changed=build.rs"); 603 println!("cargo:rerun-if-changed=build.rs");
602} 604}
603//- src/main.rs 605//- src/main.rs
604include!(concat!(env!("OUT_DIR"), "/hello.rs")); 606include!(concat!(env!("OUT_DIR"), "/hello.rs"));
605 607
608#[cfg(atom_cfg)]
609struct A;
610#[cfg(bad_atom_cfg)]
611struct A;
612#[cfg(featlike = "set")]
613struct B;
614#[cfg(featlike = "not_set")]
615struct B;
616
617fn main() {
618 let va = A;
619 let vb = B;
620 message();
621}
622
606fn main() { message(); } 623fn main() { message(); }
607"###, 624"###,
608 ) 625 )
@@ -614,12 +631,98 @@ fn main() { message(); }
614 let res = server.send_request::<GotoDefinition>(GotoDefinitionParams { 631 let res = server.send_request::<GotoDefinition>(GotoDefinitionParams {
615 text_document_position_params: TextDocumentPositionParams::new( 632 text_document_position_params: TextDocumentPositionParams::new(
616 server.doc_id("src/main.rs"), 633 server.doc_id("src/main.rs"),
617 Position::new(2, 15), 634 Position::new(14, 8),
618 ), 635 ),
619 work_done_progress_params: Default::default(), 636 work_done_progress_params: Default::default(),
620 partial_result_params: Default::default(), 637 partial_result_params: Default::default(),
621 }); 638 });
622 assert!(format!("{}", res).contains("hello.rs")); 639 assert!(format!("{}", res).contains("hello.rs"));
640 server.request::<GotoTypeDefinition>(
641 GotoDefinitionParams {
642 text_document_position_params: TextDocumentPositionParams::new(
643 server.doc_id("src/main.rs"),
644 Position::new(12, 9),
645 ),
646 work_done_progress_params: Default::default(),
647 partial_result_params: Default::default(),
648 },
649 json!([{
650 "originSelectionRange": {
651 "end": {
652 "character": 10,
653 "line": 12
654 },
655 "start": {
656 "character": 8,
657 "line": 12
658 }
659 },
660 "targetRange": {
661 "end": {
662 "character": 9,
663 "line": 3
664 },
665 "start": {
666 "character": 0,
667 "line": 2
668 }
669 },
670 "targetSelectionRange": {
671 "end": {
672 "character": 8,
673 "line": 3
674 },
675 "start": {
676 "character": 7,
677 "line": 3
678 }
679 },
680 "targetUri": "file:///[..]src/main.rs"
681 }]),
682 );
683 server.request::<GotoTypeDefinition>(
684 GotoDefinitionParams {
685 text_document_position_params: TextDocumentPositionParams::new(
686 server.doc_id("src/main.rs"),
687 Position::new(13, 9),
688 ),
689 work_done_progress_params: Default::default(),
690 partial_result_params: Default::default(),
691 },
692 json!([{
693 "originSelectionRange": {
694 "end": {
695 "character": 10,
696 "line": 13
697 },
698 "start": {
699 "character": 8,
700 "line":13
701 }
702 },
703 "targetRange": {
704 "end": {
705 "character": 9,
706 "line": 7
707 },
708 "start": {
709 "character": 0,
710 "line":6
711 }
712 },
713 "targetSelectionRange": {
714 "end": {
715 "character": 8,
716 "line": 7
717 },
718 "start": {
719 "character": 7,
720 "line": 7
721 }
722 },
723 "targetUri": "file:///[..]src/main.rs"
724 }]),
725 );
623} 726}
624 727
625#[test] 728#[test]
@@ -708,135 +811,3 @@ pub fn foo(_input: TokenStream) -> TokenStream {
708 let value = res.get("contents").unwrap().get("value").unwrap().to_string(); 811 let value = res.get("contents").unwrap().get("value").unwrap().to_string();
709 assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#) 812 assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#)
710} 813}
711
712#[test]
713fn build_rs_cfgs() {
714 if skip_slow_tests() {
715 return;
716 }
717
718 let server = Project::with_fixture(
719 r###"
720//- Cargo.toml
721[package]
722name = "foo"
723version = "0.0.0"
724
725//- build.rs
726
727fn main() {
728 println!("cargo:rustc-cfg=atom_cfg");
729 println!("cargo:rustc-cfg=featlike=\"set\"");
730 println!("cargo:rerun-if-changed=build.rs");
731}
732//- src/main.rs
733#[cfg(atom_cfg)]
734struct A;
735
736#[cfg(bad_atom_cfg)]
737struct A;
738
739#[cfg(featlike = "set")]
740struct B;
741
742#[cfg(featlike = "not_set")]
743struct B;
744
745fn main() {
746 let va = A;
747 let vb = B;
748}
749"###,
750 )
751 .with_config(|config| {
752 config.cargo.load_out_dirs_from_check = true;
753 })
754 .server();
755 server.wait_until_workspace_is_loaded();
756 server.request::<GotoTypeDefinition>(
757 GotoDefinitionParams {
758 text_document_position_params: TextDocumentPositionParams::new(
759 server.doc_id("src/main.rs"),
760 Position::new(13, 9),
761 ),
762 work_done_progress_params: Default::default(),
763 partial_result_params: Default::default(),
764 },
765 json!([{
766 "originSelectionRange": {
767 "end": {
768 "character": 10,
769 "line": 13
770 },
771 "start": {
772 "character": 8,
773 "line":13
774 }
775 },
776 "targetRange": {
777 "end": {
778 "character": 9,
779 "line": 1
780 },
781 "start": {
782 "character": 0,
783 "line":0
784 }
785 },
786 "targetSelectionRange": {
787 "end": {
788 "character": 8,
789 "line": 1
790 },
791 "start": {
792 "character": 7,
793 "line": 1
794 }
795 },
796 "targetUri": "file:///[..]src/main.rs"
797 }]),
798 );
799 server.request::<GotoTypeDefinition>(
800 GotoDefinitionParams {
801 text_document_position_params: TextDocumentPositionParams::new(
802 server.doc_id("src/main.rs"),
803 Position::new(14, 9),
804 ),
805 work_done_progress_params: Default::default(),
806 partial_result_params: Default::default(),
807 },
808 json!([{
809 "originSelectionRange": {
810 "end": {
811 "character": 10,
812 "line": 14
813 },
814 "start": {
815 "character": 8,
816 "line":14
817 }
818 },
819 "targetRange": {
820 "end": {
821 "character": 9,
822 "line": 7
823 },
824 "start": {
825 "character": 0,
826 "line":6
827 }
828 },
829 "targetSelectionRange": {
830 "end": {
831 "character": 8,
832 "line": 7
833 },
834 "start": {
835 "character": 7,
836 "line": 7
837 }
838 },
839 "targetUri": "file:///[..]src/main.rs"
840 }]),
841 );
842}