Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/hover/tests.rs')
-rw-r--r--crates/ide/src/hover/tests.rs123
1 files changed, 92 insertions, 31 deletions
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 326c248b7a..f17a0fa2cd 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -18,7 +18,8 @@ const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
format: HoverDocFormat::Markdown,
keywords: true,
max_trait_assoc_items_count: None,
- max_adt_fields_or_variants_count: Some(5),
+ max_struct_or_union_fields_count: Some(5),
+ max_enum_variants_count: Some(5),
};
fn check_hover_no_result(ra_fixture: &str) {
@@ -51,8 +52,8 @@ fn check(ra_fixture: &str, expect: Expect) {
}
#[track_caller]
-fn check_hover_adt_fields_or_variants_limit(
- count: Option<usize>,
+fn check_hover_struct_or_union_fields_limit(
+ fields_count: impl Into<Option<usize>>,
ra_fixture: &str,
expect: Expect,
) {
@@ -61,7 +62,33 @@ fn check_hover_adt_fields_or_variants_limit(
.hover(
&HoverConfig {
links_in_hover: true,
- max_adt_fields_or_variants_count: count,
+ max_struct_or_union_fields_count: fields_count.into(),
+ ..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_hover_enum_variants_limit(
+ variants_count: impl Into<Option<usize>>,
+ ra_fixture: &str,
+ expect: Expect,
+) {
+ let (analysis, position) = fixture::position(ra_fixture);
+ let hover = analysis
+ .hover(
+ &HoverConfig {
+ links_in_hover: true,
+ max_enum_variants_count: variants_count.into(),
..HOVER_BASE_CONFIG
},
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
@@ -912,8 +939,8 @@ struct Foo$0 where u32: Copy { field: u32 }
#[test]
fn hover_record_struct_limit() {
- check_hover_adt_fields_or_variants_limit(
- Some(3),
+ check_hover_struct_or_union_fields_limit(
+ 3,
r#"
struct Foo$0 { a: u32, b: i32, c: i32 }
"#,
@@ -934,8 +961,8 @@ fn hover_record_struct_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(3),
+ check_hover_struct_or_union_fields_limit(
+ 3,
r#"
struct Foo$0 { a: u32 }
"#,
@@ -954,8 +981,8 @@ fn hover_record_struct_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(3),
+ check_hover_struct_or_union_fields_limit(
+ 3,
r#"
struct Foo$0 { a: u32, b: i32, c: i32, d: u32 }
"#,
@@ -977,7 +1004,7 @@ fn hover_record_struct_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
+ check_hover_struct_or_union_fields_limit(
None,
r#"
struct Foo$0 { a: u32, b: i32, c: i32 }
@@ -995,8 +1022,8 @@ fn hover_record_struct_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(0),
+ check_hover_struct_or_union_fields_limit(
+ 0,
r#"
struct Foo$0 { a: u32, b: i32, c: i32 }
"#,
@@ -1017,8 +1044,8 @@ fn hover_record_struct_limit() {
#[test]
fn hover_enum_limit() {
- check_hover_adt_fields_or_variants_limit(
- Some(5),
+ check_hover_enum_variants_limit(
+ 5,
r#"enum Foo$0 { A, B }"#,
expect![[r#"
*Foo*
@@ -1036,8 +1063,8 @@ fn hover_enum_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(1),
+ check_hover_enum_variants_limit(
+ 1,
r#"enum Foo$0 { A, B }"#,
expect![[r#"
*Foo*
@@ -1055,8 +1082,8 @@ fn hover_enum_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(0),
+ check_hover_enum_variants_limit(
+ 0,
r#"enum Foo$0 { A, B }"#,
expect![[r#"
*Foo*
@@ -1071,7 +1098,7 @@ fn hover_enum_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
+ check_hover_enum_variants_limit(
None,
r#"enum Foo$0 { A, B }"#,
expect![[r#"
@@ -1087,12 +1114,46 @@ fn hover_enum_limit() {
```
"#]],
);
+ check_hover_enum_variants_limit(
+ 7,
+ r#"enum Enum$0 {
+ Variant {},
+ Variant2 { field: i32 },
+ Variant3 { field: i32, field2: i32 },
+ Variant4(),
+ Variant5(i32),
+ Variant6(i32, i32),
+ Variant7,
+ Variant8,
+ }"#,
+ expect![[r#"
+ *Enum*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ // size = 12 (0xC), align = 4, niches = 4294967288
+ enum Enum {
+ Variant {},
+ Variant2 { /* … */ },
+ Variant3 { /* … */ },
+ Variant4(),
+ Variant5( /* … */ ),
+ Variant6( /* … */ ),
+ Variant7,
+ /* … */
+ }
+ ```
+ "#]],
+ );
}
#[test]
fn hover_union_limit() {
- check_hover_adt_fields_or_variants_limit(
- Some(5),
+ check_hover_struct_or_union_fields_limit(
+ 5,
r#"union Foo$0 { a: u32, b: i32 }"#,
expect![[r#"
*Foo*
@@ -1110,8 +1171,8 @@ fn hover_union_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(1),
+ check_hover_struct_or_union_fields_limit(
+ 1,
r#"union Foo$0 { a: u32, b: i32 }"#,
expect![[r#"
*Foo*
@@ -1129,8 +1190,8 @@ fn hover_union_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
- Some(0),
+ check_hover_struct_or_union_fields_limit(
+ 0,
r#"union Foo$0 { a: u32, b: i32 }"#,
expect![[r#"
*Foo*
@@ -1145,7 +1206,7 @@ fn hover_union_limit() {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
+ check_hover_struct_or_union_fields_limit(
None,
r#"union Foo$0 { a: u32, b: i32 }"#,
expect![[r#"
@@ -1630,12 +1691,12 @@ impl Thing {
```
"#]],
);
- check_hover_adt_fields_or_variants_limit(
+ check_hover_struct_or_union_fields_limit(
None,
r#"
struct Thing { x: u32 }
impl Thing {
- fn new() -> Self { Self$0 { x: 0 } }
+ fn new() -> Self$0 { Self { x: 0 } }
}
"#,
expect![[r#"
@@ -2599,8 +2660,8 @@ fn test_hover_layout_of_enum() {
```rust
// size = 16 (0x10), align = 8, niches = 254
enum Foo {
- Variant1(u8, u16),
- Variant2(i32, u8, i64),
+ Variant1( /* … */ ),
+ Variant2( /* … */ ),
}
```
"#]],