fix: use pretty_print_pat for params in fn

This commit is contained in:
roife 2024-09-09 03:53:09 +08:00
parent 60c42c25c7
commit 5caa56e18a
2 changed files with 123 additions and 5 deletions

View file

@ -8742,3 +8742,118 @@ fn foo() {
"#]],
);
}
#[test]
fn test_hover_function_with_pat_param() {
check(
r#"fn test_1$0((start_range, end_range): (u32, u32), a: i32) {}"#,
expect![[r#"
*test_1*
```rust
test
```
```rust
fn test_1((start_range, end_range): (u32, u32), a: i32)
```
"#]],
);
// Test case with tuple pattern and mutable parameters
check(
r#"fn test_2$0((mut x, y): (i32, i32)) {}"#,
expect![[r#"
*test_2*
```rust
test
```
```rust
fn test_2((mut x, y): (i32, i32))
```
"#]],
);
// Test case with a pattern in a reference type
check(
r#"fn test_3$0(&(a, b): &(i32, i32)) {}"#,
expect![[r#"
*test_3*
```rust
test
```
```rust
fn test_3(&(a, b): &(i32, i32))
```
"#]],
);
// Test case with complex pattern (struct destructuring)
check(
r#"struct Point { x: i32, y: i32 } fn test_4$0(Point { x, y }: Point) {}"#,
expect![[r#"
*test_4*
```rust
test
```
```rust
fn test_4(Point { x: x, y: y, }: Point)
```
"#]],
);
// Test case with a nested pattern
check(
r#"fn test_5$0(((a, b), c): ((i32, i32), i32)) {}"#,
expect![[r#"
*test_5*
```rust
test
```
```rust
fn test_5(((a, b), c): ((i32, i32), i32))
```
"#]],
);
// Test case with an unused variable in the pattern
check(
r#"fn test_6$0((_, y): (i32, i64)) {}"#,
expect![[r#"
*test_6*
```rust
test
```
```rust
fn test_6((_, y): (i32, i64))
```
"#]],
);
// Test case with a complex pattern involving both tuple and struct
check(
r#"struct Foo { a: i32, b: i32 } fn test_7$0((x, Foo { a, b }): (i32, Foo)) {}"#,
expect![[r#"
*test_7*
```rust
test
```
```rust
fn test_7((x, Foo { a: a, b: b, }): (i32, Foo))
```
"#]],
);
}