Skip to content

Commit 20f4e4f

Browse files
ankddevlpil
authored andcommitted
chore: write tests + snapshots
1 parent 1c1d090 commit 20f4e4f

5 files changed

+168
-0
lines changed

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

Lines changed: 54 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";
@@ -11166,5 +11167,58 @@ fn merge_case_branch_does_not_merge_branches_with_variables_with_same_name_and_d
1116611167
}
1116711168
}"#,
1116811169
find_position_of("Ok").select_until(find_position_of("Error"))
11170+
}
11171+
11172+
fn annotate_all_top_level_definitions_dont_affect_local_vars() {
11173+
assert_code_action!(
11174+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
11175+
r#"
11176+
pub const answer = 42
11177+
11178+
pub fn add_two(thing) {
11179+
thing + 2
11180+
11181+
pub fn add_one(thing) {
11182+
let result = thing + 1
11183+
result
11184+
}
11185+
"#,
11186+
find_position_of("fn").select_until(find_position_of("("));
11187+
}
11188+
11189+
#[test]
11190+
fn annotate_all_top_level_definitions_constant() {
11191+
assert_code_action!(
11192+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
11193+
r#"
11194+
pub const answer = 42
11195+
11196+
pub fn add_two(thing) {
11197+
thing + 2
11198+
}
11199+
11200+
pub fn add_one(thing) {
11201+
thing + 1
11202+
}
11203+
"#,
11204+
find_position_of("const").select_until(find_position_of("="))
11205+
);
11206+
}
11207+
11208+
11209+
#[test]
11210+
fn annotate_all_top_level_definitions_function() {
11211+
assert_code_action!(
11212+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
11213+
r#"
11214+
pub fn add_two(thing) {
11215+
thing + 2
11216+
}
11217+
11218+
pub fn add_one(thing) {
11219+
thing + 1
11220+
}
11221+
"#,
11222+
find_position_of("fn").select_until(find_position_of("("))
1116911223
);
1117011224
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
source: compiler-core/src/language_server/tests/action.rs
3+
assertion_line: 2928
4+
expression: "\npub const my_constant = 20\n\npub fn add_my_constant(value) {\n let result = value + my_constant\n result\n}\n"
5+
snapshot_kind: text
6+
---
7+
----- BEFORE ACTION
8+
9+
pub const my_constant = 20
10+
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
11+
12+
pub fn add_my_constant(value) {
13+
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
14+
let result = value + my_constant
15+
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
16+
result
17+
▔▔▔▔▔▔▔▔
18+
}
19+
20+
21+
22+
----- AFTER ACTION
23+
24+
pub const my_constant: Int = 20
25+
26+
pub fn add_my_constant(value: Int) -> Int {
27+
let result = value + my_constant
28+
result
29+
}
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+
}
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+
}
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)