Skip to content

Commit c388520

Browse files
committed
test: write more tests for code action
1 parent 76d2b96 commit c388520

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
@@ -10768,3 +10768,68 @@ pub fn add_one(thing) {
1076810768
find_position_of("fn").select_until(find_position_of("("))
1076910769
);
1077010770
}
10771+
10772+
fn annotate_all_top_level_definitions_already_annotated() {
10773+
assert_no_code_actions!(
10774+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10775+
r#"
10776+
pub const answer: Int = 42
10777+
10778+
pub fn add_two(thing: Int) -> {
10779+
thing + 2
10780+
}
10781+
10782+
pub fn add_one(thing: Int) -> Int {
10783+
thing + 1
10784+
}
10785+
"#,
10786+
find_position_of("fn").select_until(find_position_of("("))
10787+
);
10788+
}
10789+
10790+
#[test]
10791+
fn annotate_all_top_level_definitions_inside_body() {
10792+
assert_no_code_actions!(
10793+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10794+
r#"
10795+
pub fn add_one(thing) {
10796+
thing + 1
10797+
}
10798+
"#,
10799+
find_position_of("fn").select_until(find_position_of("("))
10800+
);
10801+
}
10802+
10803+
#[test]
10804+
fn annotate_all_top_level_definitions_partially_annotated() {
10805+
assert_code_action!(
10806+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
10807+
r#"
10808+
pub const answer: Int = 42
10809+
pub const another_answer = 43
10810+
10811+
pub fn add_two(thing) -> Int {
10812+
thing + 2
10813+
}
10814+
10815+
pub fn add_one(thing: Int) {
10816+
thing + 1
10817+
}
10818+
"#,
10819+
find_position_of("fn").select_until(find_position_of("("))
10820+
);
10821+
}
10822+
10823+
// FIXME: make test working
10824+
// #[test]
10825+
// fn annotate_all_top_level_definitions_with_two_generic_functions() {
10826+
// assert_code_action!(
10827+
// ANNOTATE_TOP_LEVEL_DEFINITIONS,
10828+
// r#"
10829+
// fn wibble(one) { todo }
10830+
10831+
// fn wobble(other) { todo }
10832+
// "#,
10833+
// find_position_of("wobble").to_selection()
10834+
// );
10835+
// }
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)