Skip to content

Commit 04db078

Browse files
committed
test: write more tests for code action
1 parent 88bad10 commit 04db078

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10591,3 +10591,69 @@ pub fn add_one(thing) {
1059110591
find_position_of("const").select_until(find_position_of("="))
1059210592
);
1059310593
}
10594+
10595+
#[test]
10596+
fn annotate_all_top_level_definitions_already_annotated() {
10597+
assert_no_code_actions!(
10598+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10599+
r#"
10600+
pub const answer: Int = 42
10601+
10602+
pub fn add_two(thing: Int) -> {
10603+
thing + 2
10604+
}
10605+
10606+
pub fn add_one(thing: Int) -> Int {
10607+
thing + 1
10608+
}
10609+
"#,
10610+
find_position_of("fn").select_until(find_position_of("("))
10611+
);
10612+
}
10613+
10614+
#[test]
10615+
fn annotate_all_top_level_definitions_inside_body() {
10616+
assert_no_code_actions!(
10617+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10618+
r#"
10619+
pub fn add_one(thing) {
10620+
thing + 1
10621+
}
10622+
"#,
10623+
find_position_of("fn").select_until(find_position_of("("))
10624+
);
10625+
}
10626+
10627+
#[test]
10628+
fn annotate_all_top_level_definitions_partially_annotated() {
10629+
assert_code_action!(
10630+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10631+
r#"
10632+
pub const answer: Int = 42
10633+
pub const another_answer = 43
10634+
10635+
pub fn add_two(thing) -> Int {
10636+
thing + 2
10637+
}
10638+
10639+
pub fn add_one(thing: Int) {
10640+
thing + 1
10641+
}
10642+
"#,
10643+
find_position_of("fn").select_until(find_position_of("("))
10644+
);
10645+
}
10646+
10647+
// FIXME: make test working
10648+
// #[test]
10649+
// fn annotate_all_top_level_definitions_with_two_generic_functions() {
10650+
// assert_code_action!(
10651+
// ANNOTATE_TOP_LEVEL_DEFINITIONS,
10652+
// r#"
10653+
// fn wibble(one) { todo }
10654+
10655+
// fn wobble(other) { todo }
10656+
// "#,
10657+
// find_position_of("wobble").to_selection()
10658+
// );
10659+
// }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
expression: "\npub const answer: Int = 42\npub const another_answer = 43\n\npub fn add_two(thing) -> Int {\n thing + 2\n}\n\npub fn add_one(thing: Int) {\n thing + 1\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
7+
pub const answer: Int = 42
8+
pub const another_answer = 43
9+
10+
pub fn add_two(thing) -> Int {
11+
▔▔▔▔▔▔▔▔▔▔↑
12+
thing + 2
13+
}
14+
15+
pub fn add_one(thing: Int) {
16+
thing + 1
17+
}
18+
19+
20+
----- AFTER ACTION
21+
22+
pub const answer: Int = 42
23+
pub const another_answer: Int = 43
24+
25+
pub fn add_two(thing: Int) -> Int {
26+
thing + 2
27+
}
28+
29+
pub fn add_one(thing: Int) -> Int {
30+
thing + 1
31+
}

0 commit comments

Comments
 (0)