Skip to content

Commit 90078da

Browse files
committed
test: write more tests for code action
1 parent e10c0a5 commit 90078da

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10692,3 +10692,68 @@ pub fn add_one(thing) {
1069210692
find_position_of("fn").select_until(find_position_of("("))
1069310693
);
1069410694
}
10695+
10696+
fn annotate_all_top_level_definitions_already_annotated() {
10697+
assert_no_code_actions!(
10698+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10699+
r#"
10700+
pub const answer: Int = 42
10701+
10702+
pub fn add_two(thing: Int) -> {
10703+
thing + 2
10704+
}
10705+
10706+
pub fn add_one(thing: Int) -> Int {
10707+
thing + 1
10708+
}
10709+
"#,
10710+
find_position_of("fn").select_until(find_position_of("("))
10711+
);
10712+
}
10713+
10714+
#[test]
10715+
fn annotate_all_top_level_definitions_inside_body() {
10716+
assert_no_code_actions!(
10717+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10718+
r#"
10719+
pub fn add_one(thing) {
10720+
thing + 1
10721+
}
10722+
"#,
10723+
find_position_of("fn").select_until(find_position_of("("))
10724+
);
10725+
}
10726+
10727+
#[test]
10728+
fn annotate_all_top_level_definitions_partially_annotated() {
10729+
assert_code_action!(
10730+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10731+
r#"
10732+
pub const answer: Int = 42
10733+
pub const another_answer = 43
10734+
10735+
pub fn add_two(thing) -> Int {
10736+
thing + 2
10737+
}
10738+
10739+
pub fn add_one(thing: Int) {
10740+
thing + 1
10741+
}
10742+
"#,
10743+
find_position_of("fn").select_until(find_position_of("("))
10744+
);
10745+
}
10746+
10747+
// FIXME: make test working
10748+
// #[test]
10749+
// fn annotate_all_top_level_definitions_with_two_generic_functions() {
10750+
// assert_code_action!(
10751+
// ANNOTATE_TOP_LEVEL_DEFINITIONS,
10752+
// r#"
10753+
// fn wibble(one) { todo }
10754+
10755+
// fn wobble(other) { todo }
10756+
// "#,
10757+
// find_position_of("wobble").to_selection()
10758+
// );
10759+
// }
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)