Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide/src/hover/tests.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 463f0951ea..192f6c0272 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -51,6 +51,28 @@ fn check(ra_fixture: &str, expect: Expect) {
}
#[track_caller]
+fn check_hover_struct_limit(count: usize, ra_fixture: &str, expect: Expect) {
+ let (analysis, position) = fixture::position(ra_fixture);
+ let hover = analysis
+ .hover(
+ &HoverConfig {
+ links_in_hover: true,
+ max_struct_field_count: Some(count),
+ ..HOVER_BASE_CONFIG
+ },
+ FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
+ )
+ .unwrap()
+ .unwrap();
+
+ let content = analysis.db.file_text(position.file_id);
+ let hovered_element = &content[hover.range];
+
+ let actual = format!("*{hovered_element}*\n{}\n", hover.info.markup);
+ expect.assert_eq(&actual)
+}
+
+#[track_caller]
fn check_assoc_count(count: usize, ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let hover = analysis
@@ -880,6 +902,75 @@ struct Foo$0 where u32: Copy { field: u32 }
}
#[test]
+fn hover_record_struct_limit() {
+ check_hover_struct_limit(
+ 3,
+ r#"
+ struct Foo$0 { a: u32, b: i32, c: i32 }
+ "#,
+ expect![[r#"
+ *Foo*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ // size = 12 (0xC), align = 4
+ struct Foo {
+ a: u32,
+ b: i32,
+ c: i32,
+ }
+ ```
+ "#]],
+ );
+ check_hover_struct_limit(
+ 3,
+ r#"
+ struct Foo$0 { a: u32 }
+ "#,
+ expect![[r#"
+ *Foo*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ // size = 4, align = 4
+ struct Foo {
+ a: u32,
+ }
+ ```
+ "#]],
+ );
+ check_hover_struct_limit(
+ 3,
+ r#"
+ struct Foo$0 { a: u32, b: i32, c: i32, d: u32 }
+ "#,
+ expect![[r#"
+ *Foo*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ // size = 16 (0x10), align = 4
+ struct Foo {
+ a: u32,
+ b: i32,
+ c: i32,
+ /* … */
+ }
+ ```
+ "#]],
+ );
+}
+
+#[test]
fn hover_unit_struct() {
check(
r#"