Skip to content

Commit 5c6aa88

Browse files
committed
add tests for unwrapping functions with labelled arguments
1 parent f3eb218 commit 5c6aa88

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
@@ -10011,6 +10011,56 @@ fn mi(v) {
1001110011
);
1001210012
}
1001310013

10014+
#[test]
10015+
fn unwrap_anonymous_function_with_labelled_args() {
10016+
assert_code_action!(
10017+
UNWRAP_ANONYMOUS_FUNCTION,
10018+
"pub fn main() {
10019+
fn(a, b) { op(first: a, second: b) }
10020+
}
10021+
10022+
fn op(first a, second b) {
10023+
todo
10024+
}
10025+
",
10026+
find_position_of("fn(a, b)").to_selection()
10027+
);
10028+
}
10029+
10030+
#[test]
10031+
fn unwrap_anonymous_function_with_labelled_and_unlabelled_args() {
10032+
assert_code_action!(
10033+
UNWRAP_ANONYMOUS_FUNCTION,
10034+
"pub fn main() {
10035+
fn(a, b, c) { op(a, second: b, third: c) }
10036+
}
10037+
10038+
fn op(a, second b, third c) {
10039+
todo
10040+
}
10041+
",
10042+
find_position_of("fn(a, b, c)").to_selection()
10043+
);
10044+
}
10045+
10046+
#[test]
10047+
fn unwrap_anonymous_function_with_labelled_args_out_of_order() {
10048+
assert_code_action!(
10049+
UNWRAP_ANONYMOUS_FUNCTION,
10050+
"pub fn main() {
10051+
fn(a, b) { op(second: b, first: a) }
10052+
}
10053+
10054+
fn op(first a, second b) {
10055+
todo
10056+
}
10057+
",
10058+
find_position_of("fn(a, b)").to_selection()
10059+
);
10060+
}
10061+
10062+
10063+
1001410064
#[test]
1001510065
fn unwrap_anonymous_function_unavailable_when_args_discarded() {
1001610066
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)