Skip to content

Commit 78f447f

Browse files
committed
test: write more tests for code action
1 parent e6d548f commit 78f447f

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
@@ -10741,3 +10741,68 @@ pub fn add_one(thing) {
1074110741
find_position_of("fn").select_until(find_position_of("("))
1074210742
);
1074310743
}
10744+
10745+
fn annotate_all_top_level_definitions_already_annotated() {
10746+
assert_no_code_actions!(
10747+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10748+
r#"
10749+
pub const answer: Int = 42
10750+
10751+
pub fn add_two(thing: Int) -> {
10752+
thing + 2
10753+
}
10754+
10755+
pub fn add_one(thing: Int) -> Int {
10756+
thing + 1
10757+
}
10758+
"#,
10759+
find_position_of("fn").select_until(find_position_of("("))
10760+
);
10761+
}
10762+
10763+
#[test]
10764+
fn annotate_all_top_level_definitions_inside_body() {
10765+
assert_no_code_actions!(
10766+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10767+
r#"
10768+
pub fn add_one(thing) {
10769+
thing + 1
10770+
}
10771+
"#,
10772+
find_position_of("fn").select_until(find_position_of("("))
10773+
);
10774+
}
10775+
10776+
#[test]
10777+
fn annotate_all_top_level_definitions_partially_annotated() {
10778+
assert_code_action!(
10779+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10780+
r#"
10781+
pub const answer: Int = 42
10782+
pub const another_answer = 43
10783+
10784+
pub fn add_two(thing) -> Int {
10785+
thing + 2
10786+
}
10787+
10788+
pub fn add_one(thing: Int) {
10789+
thing + 1
10790+
}
10791+
"#,
10792+
find_position_of("fn").select_until(find_position_of("("))
10793+
);
10794+
}
10795+
10796+
// FIXME: make test working
10797+
// #[test]
10798+
// fn annotate_all_top_level_definitions_with_two_generic_functions() {
10799+
// assert_code_action!(
10800+
// ANNOTATE_TOP_LEVEL_DEFINITIONS,
10801+
// r#"
10802+
// fn wibble(one) { todo }
10803+
10804+
// fn wobble(other) { todo }
10805+
// "#,
10806+
// find_position_of("wobble").to_selection()
10807+
// );
10808+
// }
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)