aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-30 20:57:34 +0100
committerGitHub <[email protected]>2020-06-30 20:57:34 +0100
commitbad0b9aa23d2e72366922ec00d50043db0bae338 (patch)
treefbe6d93874ad40f3c3eb333591ac90e6f6fd0f88 /crates
parent569c59b9754683967ad6c475d8cd8963cca072f6 (diff)
parent8b725a2f77d56ce7f7e7631070573541ff228e8d (diff)
Merge #5151
5151: Switch to expect for the rest of inlay tests r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs174
1 files changed, 100 insertions, 74 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 64980a832..62d364bfa 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -345,7 +345,7 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
345 345
346#[cfg(test)] 346#[cfg(test)]
347mod tests { 347mod tests {
348 use insta::assert_debug_snapshot; 348 use expect::{expect, Expect};
349 use test_utils::extract_annotations; 349 use test_utils::extract_annotations;
350 350
351 use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file}; 351 use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file};
@@ -363,6 +363,12 @@ mod tests {
363 assert_eq!(expected, actual); 363 assert_eq!(expected, actual);
364 } 364 }
365 365
366 fn check_expect(ra_fixture: &str, config: InlayHintsConfig, expect: Expect) {
367 let (analysis, file_id) = single_file(ra_fixture);
368 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
369 expect.assert_debug_eq(&inlay_hints)
370 }
371
366 #[test] 372 #[test]
367 fn param_hints_only() { 373 fn param_hints_only() {
368 check_with_config( 374 check_with_config(
@@ -772,34 +778,41 @@ fn main() {
772 778
773 #[test] 779 #[test]
774 fn chaining_hints_ignore_comments() { 780 fn chaining_hints_ignore_comments() {
775 let (analysis, file_id) = single_file( 781 check_expect(
776 r#" 782 r#"
777 struct A(B); 783struct A(B);
778 impl A { fn into_b(self) -> B { self.0 } } 784impl A { fn into_b(self) -> B { self.0 } }
779 struct B(C); 785struct B(C);
780 impl B { fn into_c(self) -> C { self.0 } } 786impl B { fn into_c(self) -> C { self.0 } }
781 struct C; 787struct C;
782 788
783 fn main() { 789fn main() {
784 let c = A(B(C)) 790 let c = A(B(C))
785 .into_b() // This is a comment 791 .into_b() // This is a comment
786 .into_c(); 792 .into_c();
787 }"#, 793}
788 ); 794"#,
789 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" 795 InlayHintsConfig {
790 [ 796 parameter_hints: false,
791 InlayHint { 797 type_hints: false,
792 range: 147..172, 798 chaining_hints: true,
793 kind: ChainingHint, 799 max_length: None,
794 label: "B",
795 },
796 InlayHint {
797 range: 147..154,
798 kind: ChainingHint,
799 label: "A",
800 }, 800 },
801 ] 801 expect![[r#"
802 "###); 802 [
803 InlayHint {
804 range: 147..172,
805 kind: ChainingHint,
806 label: "B",
807 },
808 InlayHint {
809 range: 147..154,
810 kind: ChainingHint,
811 label: "A",
812 },
813 ]
814 "#]],
815 );
803 } 816 }
804 817
805 #[test] 818 #[test]
@@ -826,7 +839,7 @@ fn main() {
826 839
827 #[test] 840 #[test]
828 fn struct_access_chaining_hints() { 841 fn struct_access_chaining_hints() {
829 let (analysis, file_id) = single_file( 842 check_expect(
830 r#" 843 r#"
831struct A { pub b: B } 844struct A { pub b: B }
832struct B { pub c: C } 845struct B { pub c: C }
@@ -845,58 +858,71 @@ fn main() {
845 let x = D 858 let x = D
846 .foo(); 859 .foo();
847}"#, 860}"#,
848 ); 861 InlayHintsConfig {
849 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" 862 parameter_hints: false,
850 [ 863 type_hints: false,
851 InlayHint { 864 chaining_hints: true,
852 range: 143..190, 865 max_length: None,
853 kind: ChainingHint,
854 label: "C",
855 },
856 InlayHint {
857 range: 143..179,
858 kind: ChainingHint,
859 label: "B",
860 }, 866 },
861 ] 867 expect![[r#"
862 "###); 868 [
869 InlayHint {
870 range: 143..190,
871 kind: ChainingHint,
872 label: "C",
873 },
874 InlayHint {
875 range: 143..179,
876 kind: ChainingHint,
877 label: "B",
878 },
879 ]
880 "#]],
881 );
863 } 882 }
864 883
865 #[test] 884 #[test]
866 fn generic_chaining_hints() { 885 fn generic_chaining_hints() {
867 let (analysis, file_id) = single_file( 886 check_expect(
868 r#" 887 r#"
869 struct A<T>(T); 888struct A<T>(T);
870 struct B<T>(T); 889struct B<T>(T);
871 struct C<T>(T); 890struct C<T>(T);
872 struct X<T,R>(T, R); 891struct X<T,R>(T, R);
873 892
874 impl<T> A<T> { 893impl<T> A<T> {
875 fn new(t: T) -> Self { A(t) } 894 fn new(t: T) -> Self { A(t) }
876 fn into_b(self) -> B<T> { B(self.0) } 895 fn into_b(self) -> B<T> { B(self.0) }
877 } 896}
878 impl<T> B<T> { 897impl<T> B<T> {
879 fn into_c(self) -> C<T> { C(self.0) } 898 fn into_c(self) -> C<T> { C(self.0) }
880 } 899}
881 fn main() { 900fn main() {
882 let c = A::new(X(42, true)) 901 let c = A::new(X(42, true))
883 .into_b() 902 .into_b()
884 .into_c(); 903 .into_c();
885 }"#, 904}
886 ); 905"#,
887 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" 906 InlayHintsConfig {
888 [ 907 parameter_hints: false,
889 InlayHint { 908 type_hints: false,
890 range: 246..283, 909 chaining_hints: true,
891 kind: ChainingHint, 910 max_length: None,
892 label: "B<X<i32, bool>>",
893 },
894 InlayHint {
895 range: 246..265,
896 kind: ChainingHint,
897 label: "A<X<i32, bool>>",
898 }, 911 },
899 ] 912 expect![[r#"
900 "###); 913 [
914 InlayHint {
915 range: 246..283,
916 kind: ChainingHint,
917 label: "B<X<i32, bool>>",
918 },
919 InlayHint {
920 range: 246..265,
921 kind: ChainingHint,
922 label: "A<X<i32, bool>>",
923 },
924 ]
925 "#]],
926 );
901 } 927 }
902} 928}