Skip to content

Commit 6e922c5

Browse files
ankddevlpil
authored andcommitted
test: write more tests for code action
1 parent 5d22ff4 commit 6e922c5

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
@@ -11221,3 +11221,68 @@ pub fn add_one(thing) {
1122111221
find_position_of("fn").select_until(find_position_of("("))
1122211222
);
1122311223
}
11224+
11225+
fn annotate_all_top_level_definitions_already_annotated() {
11226+
assert_no_code_actions!(
11227+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
11228+
r#"
11229+
pub const answer: Int = 42
11230+
11231+
pub fn add_two(thing: Int) -> {
11232+
thing + 2
11233+
}
11234+
11235+
pub fn add_one(thing: Int) -> Int {
11236+
thing + 1
11237+
}
11238+
"#,
11239+
find_position_of("fn").select_until(find_position_of("("))
11240+
);
11241+
}
11242+
11243+
#[test]
11244+
fn annotate_all_top_level_definitions_inside_body() {
11245+
assert_no_code_actions!(
11246+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
11247+
r#"
11248+
pub fn add_one(thing) {
11249+
thing + 1
11250+
}
11251+
"#,
11252+
find_position_of("fn").select_until(find_position_of("("))
11253+
);
11254+
}
11255+
11256+
#[test]
11257+
fn annotate_all_top_level_definitions_partially_annotated() {
11258+
assert_code_action!(
11259+
ANNOTATE_TOP_LEVEL_DEFINITIONS,
11260+
r#"
11261+
pub const answer: Int = 42
11262+
pub const another_answer = 43
11263+
11264+
pub fn add_two(thing) -> Int {
11265+
thing + 2
11266+
}
11267+
11268+
pub fn add_one(thing: Int) {
11269+
thing + 1
11270+
}
11271+
"#,
11272+
find_position_of("fn").select_until(find_position_of("("))
11273+
);
11274+
}
11275+
11276+
// FIXME: make test working
11277+
// #[test]
11278+
// fn annotate_all_top_level_definitions_with_two_generic_functions() {
11279+
// assert_code_action!(
11280+
// ANNOTATE_TOP_LEVEL_DEFINITIONS,
11281+
// r#"
11282+
// fn wibble(one) { todo }
11283+
11284+
// fn wobble(other) { todo }
11285+
// "#,
11286+
// find_position_of("wobble").to_selection()
11287+
// );
11288+
// }
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)