Skip to content

Commit 3287381

Browse files
committed
chore: write tests + snapshots
1 parent f102734 commit 3287381

4 files changed

+141
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const ASSIGN_UNUSED_RESULT: &str = "Assign unused Result value to `_`";
112112
const ADD_MISSING_PATTERNS: &str = "Add missing patterns";
113113
const ADD_ANNOTATION: &str = "Add type annotation";
114114
const ADD_ANNOTATIONS: &str = "Add type annotations";
115+
const ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS: &str = "Annotate all top level type definitions";
115116
const CONVERT_FROM_USE: &str = "Convert from `use`";
116117
const CONVERT_TO_USE: &str = "Convert to `use`";
117118
const EXTRACT_VARIABLE: &str = "Extract variable";
@@ -10554,3 +10555,58 @@ pub fn main() {
1055410555
find_position_of("let c").select_until(find_position_of("* d"))
1055510556
);
1055610557
}
10558+
10559+
#[test]
10560+
fn annotate_all_top_level_definitions_function() {
10561+
assert_code_action!(
10562+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10563+
r#"
10564+
pub fn add_two(thing) {
10565+
thing + 2
10566+
}
10567+
10568+
pub fn add_one(thing) {
10569+
thing + 1
10570+
}
10571+
"#,
10572+
find_position_of("fn").select_until(find_position_of("("))
10573+
);
10574+
}
10575+
10576+
#[test]
10577+
fn annotate_all_top_level_definitions_constant() {
10578+
assert_code_action!(
10579+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10580+
r#"
10581+
pub const answer = 42
10582+
10583+
pub fn add_two(thing) {
10584+
thing + 2
10585+
}
10586+
10587+
pub fn add_one(thing) {
10588+
thing + 1
10589+
}
10590+
"#,
10591+
find_position_of("const").select_until(find_position_of("="))
10592+
);
10593+
}
10594+
10595+
#[test]
10596+
fn annotate_all_top_level_definitions_dont_affect_local_vars() {
10597+
assert_code_action!(
10598+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10599+
r#"
10600+
pub const answer = 42
10601+
10602+
pub fn add_two(thing) {
10603+
thing + 2
10604+
10605+
pub fn add_one(thing) {
10606+
let result = thing + 1
10607+
result
10608+
}
10609+
"#,
10610+
find_position_of("fn").select_until(find_position_of("("))
10611+
);
10612+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
expression: "\npub const answer = 42\n\npub fn add_two(thing) {\n thing + 2\n}\n\npub fn add_one(thing) {\n thing + 1\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
7+
pub const answer = 42
8+
▔▔▔▔▔▔▔▔▔▔▔▔▔↑
9+
10+
pub fn add_two(thing) {
11+
thing + 2
12+
}
13+
14+
pub fn add_one(thing) {
15+
thing + 1
16+
}
17+
18+
19+
----- AFTER ACTION
20+
21+
pub const answer: Int = 42
22+
23+
pub fn add_two(thing: Int) -> Int {
24+
thing + 2
25+
}
26+
27+
pub fn add_one(thing: Int) -> Int {
28+
thing + 1
29+
}
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 = 42\n\npub fn add_two(thing) {\n thing + 2\n}\n\npub fn add_one(thing) {\n let result = thing + 1\n result\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
7+
pub const answer = 42
8+
9+
pub fn add_two(thing) {
10+
▔▔▔▔▔▔▔▔▔▔↑
11+
thing + 2
12+
}
13+
14+
pub fn add_one(thing) {
15+
let result = thing + 1
16+
result
17+
}
18+
19+
20+
----- AFTER ACTION
21+
22+
pub const answer: Int = 42
23+
24+
pub fn add_two(thing: Int) -> Int {
25+
thing + 2
26+
}
27+
28+
pub fn add_one(thing: Int) -> Int {
29+
let result = thing + 1
30+
result
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
expression: "\npub fn add_two(thing) {\n thing + 2\n}\n\npub fn add_one(thing) {\n thing + 1\n}\n"
4+
---
5+
----- BEFORE ACTION
6+
7+
pub fn add_two(thing) {
8+
▔▔▔▔▔▔▔▔▔▔↑
9+
thing + 2
10+
}
11+
12+
pub fn add_one(thing) {
13+
thing + 1
14+
}
15+
16+
17+
----- AFTER ACTION
18+
19+
pub fn add_two(thing: Int) -> Int {
20+
thing + 2
21+
}
22+
23+
pub fn add_one(thing: Int) -> Int {
24+
thing + 1
25+
}

0 commit comments

Comments
 (0)