Skip to content

Commit a85e024

Browse files
committed
add tests for unwrapping functions with labelled arguments
1 parent 3bacdd3 commit a85e024

4 files changed

+119
-0
lines changed

compiler-core/src/language_server/tests/action.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9347,6 +9347,56 @@ fn mi(v) {
93479347
);
93489348
}
93499349

9350+
#[test]
9351+
fn unwrap_anonymous_function_with_labelled_args() {
9352+
assert_code_action!(
9353+
UNWRAP_ANONYMOUS_FUNCTION,
9354+
"pub fn main() {
9355+
fn(a, b) { op(first: a, second: b) }
9356+
}
9357+
9358+
fn op(first a, second b) {
9359+
todo
9360+
}
9361+
",
9362+
find_position_of("fn(a, b)").to_selection()
9363+
);
9364+
}
9365+
9366+
#[test]
9367+
fn unwrap_anonymous_function_with_labelled_and_unlabelled_args() {
9368+
assert_code_action!(
9369+
UNWRAP_ANONYMOUS_FUNCTION,
9370+
"pub fn main() {
9371+
fn(a, b, c) { op(a, second: b, third: c) }
9372+
}
9373+
9374+
fn op(a, second b, third c) {
9375+
todo
9376+
}
9377+
",
9378+
find_position_of("fn(a, b, c)").to_selection()
9379+
);
9380+
}
9381+
9382+
#[test]
9383+
fn unwrap_anonymous_function_with_labelled_args_out_of_order() {
9384+
assert_code_action!(
9385+
UNWRAP_ANONYMOUS_FUNCTION,
9386+
"pub fn main() {
9387+
fn(a, b) { op(second: b, first: a) }
9388+
}
9389+
9390+
fn op(first a, second b) {
9391+
todo
9392+
}
9393+
",
9394+
find_position_of("fn(a, b)").to_selection()
9395+
);
9396+
}
9397+
9398+
9399+
93509400
#[test]
93519401
fn unwrap_anonymous_function_unavailable_when_args_discarded() {
93529402
assert_no_code_actions!(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
expression: "pub fn main() {\n fn(a, b, c) { op(a, second: b, third: c) }\n}\n\nfn op(a, second b, third c) {\n todo\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
pub fn main() {
7+
fn(a, b, c) { op(a, second: b, third: c) }
8+
9+
}
10+
11+
fn op(a, second b, third c) {
12+
todo
13+
}
14+
15+
16+
----- AFTER ACTION
17+
pub fn main() {
18+
op
19+
}
20+
21+
fn op(a, second b, third c) {
22+
todo
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
expression: "pub fn main() {\n fn(a, b) { op(first: a, second: b) }\n}\n\nfn op(first a, second b) {\n todo\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
pub fn main() {
7+
fn(a, b) { op(first: a, second: b) }
8+
9+
}
10+
11+
fn op(first a, second b) {
12+
todo
13+
}
14+
15+
16+
----- AFTER ACTION
17+
pub fn main() {
18+
op
19+
}
20+
21+
fn op(first a, second b) {
22+
todo
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
expression: "pub fn main() {\n fn(a, b) { op(second: b, first: a) }\n}\n\nfn op(first a, second b) {\n todo\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
pub fn main() {
7+
fn(a, b) { op(second: b, first: a) }
8+
9+
}
10+
11+
fn op(first a, second b) {
12+
todo
13+
}
14+
15+
16+
----- AFTER ACTION
17+
pub fn main() {
18+
op
19+
}
20+
21+
fn op(first a, second b) {
22+
todo
23+
}

0 commit comments

Comments
 (0)