Skip to content

Commit bad0b9a

Browse files
bors[bot]matklad
andauthored
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]>
2 parents 569c59b + 8b725a2 commit bad0b9a

File tree

1 file changed

+100
-74
lines changed

1 file changed

+100
-74
lines changed

crates/ra_ide/src/inlay_hints.rs

Lines changed: 100 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
345345

346346
#[cfg(test)]
347347
mod tests {
348-
use insta::assert_debug_snapshot;
348+
use expect::{expect, Expect};
349349
use test_utils::extract_annotations;
350350

351351
use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file};
@@ -363,6 +363,12 @@ mod tests {
363363
assert_eq!(expected, actual);
364364
}
365365

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+
366372
#[test]
367373
fn param_hints_only() {
368374
check_with_config(
@@ -772,34 +778,41 @@ fn main() {
772778

773779
#[test]
774780
fn chaining_hints_ignore_comments() {
775-
let (analysis, file_id) = single_file(
781+
check_expect(
776782
r#"
777-
struct A(B);
778-
impl A { fn into_b(self) -> B { self.0 } }
779-
struct B(C);
780-
impl B { fn into_c(self) -> C { self.0 } }
781-
struct C;
782-
783-
fn main() {
784-
let c = A(B(C))
785-
.into_b() // This is a comment
786-
.into_c();
787-
}"#,
788-
);
789-
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
790-
[
791-
InlayHint {
792-
range: 147..172,
793-
kind: ChainingHint,
794-
label: "B",
795-
},
796-
InlayHint {
797-
range: 147..154,
798-
kind: ChainingHint,
799-
label: "A",
783+
struct A(B);
784+
impl A { fn into_b(self) -> B { self.0 } }
785+
struct B(C);
786+
impl B { fn into_c(self) -> C { self.0 } }
787+
struct C;
788+
789+
fn main() {
790+
let c = A(B(C))
791+
.into_b() // This is a comment
792+
.into_c();
793+
}
794+
"#,
795+
InlayHintsConfig {
796+
parameter_hints: false,
797+
type_hints: false,
798+
chaining_hints: true,
799+
max_length: None,
800800
},
801-
]
802-
"###);
801+
expect![[r#"
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+
);
803816
}
804817

805818
#[test]
@@ -826,7 +839,7 @@ fn main() {
826839

827840
#[test]
828841
fn struct_access_chaining_hints() {
829-
let (analysis, file_id) = single_file(
842+
check_expect(
830843
r#"
831844
struct A { pub b: B }
832845
struct B { pub c: C }
@@ -845,58 +858,71 @@ fn main() {
845858
let x = D
846859
.foo();
847860
}"#,
848-
);
849-
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
850-
[
851-
InlayHint {
852-
range: 143..190,
853-
kind: ChainingHint,
854-
label: "C",
855-
},
856-
InlayHint {
857-
range: 143..179,
858-
kind: ChainingHint,
859-
label: "B",
861+
InlayHintsConfig {
862+
parameter_hints: false,
863+
type_hints: false,
864+
chaining_hints: true,
865+
max_length: None,
860866
},
861-
]
862-
"###);
867+
expect![[r#"
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+
);
863882
}
864883

865884
#[test]
866885
fn generic_chaining_hints() {
867-
let (analysis, file_id) = single_file(
886+
check_expect(
868887
r#"
869-
struct A<T>(T);
870-
struct B<T>(T);
871-
struct C<T>(T);
872-
struct X<T,R>(T, R);
873-
874-
impl<T> A<T> {
875-
fn new(t: T) -> Self { A(t) }
876-
fn into_b(self) -> B<T> { B(self.0) }
877-
}
878-
impl<T> B<T> {
879-
fn into_c(self) -> C<T> { C(self.0) }
880-
}
881-
fn main() {
882-
let c = A::new(X(42, true))
883-
.into_b()
884-
.into_c();
885-
}"#,
886-
);
887-
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
888-
[
889-
InlayHint {
890-
range: 246..283,
891-
kind: ChainingHint,
892-
label: "B<X<i32, bool>>",
893-
},
894-
InlayHint {
895-
range: 246..265,
896-
kind: ChainingHint,
897-
label: "A<X<i32, bool>>",
888+
struct A<T>(T);
889+
struct B<T>(T);
890+
struct C<T>(T);
891+
struct X<T,R>(T, R);
892+
893+
impl<T> A<T> {
894+
fn new(t: T) -> Self { A(t) }
895+
fn into_b(self) -> B<T> { B(self.0) }
896+
}
897+
impl<T> B<T> {
898+
fn into_c(self) -> C<T> { C(self.0) }
899+
}
900+
fn main() {
901+
let c = A::new(X(42, true))
902+
.into_b()
903+
.into_c();
904+
}
905+
"#,
906+
InlayHintsConfig {
907+
parameter_hints: false,
908+
type_hints: false,
909+
chaining_hints: true,
910+
max_length: None,
898911
},
899-
]
900-
"###);
912+
expect![[r#"
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+
);
901927
}
902928
}

0 commit comments

Comments
 (0)