Skip to content

Commit 7ec8174

Browse files
committed
chore: write tests + snapshots
1 parent 795328c commit 7ec8174

5 files changed

+170
-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";
@@ -10686,3 +10687,58 @@ pub fn main() -> Nil {
1068610687
find_position_of("function").to_selection()
1068710688
);
1068810689
}
10690+
10691+
#[test]
10692+
fn annotate_all_top_level_definitions_dont_affect_local_vars() {
10693+
assert_code_action!(
10694+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10695+
r#"
10696+
pub const answer = 42
10697+
10698+
pub fn add_two(thing) {
10699+
thing + 2
10700+
10701+
pub fn add_one(thing) {
10702+
let result = thing + 1
10703+
result
10704+
}
10705+
"#,
10706+
find_position_of("fn").select_until(find_position_of("("));
10707+
}
10708+
10709+
#[test]
10710+
fn annotate_all_top_level_definitions_constant() {
10711+
assert_code_action!(
10712+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10713+
r#"
10714+
pub const answer = 42
10715+
10716+
pub fn add_two(thing) {
10717+
thing + 2
10718+
}
10719+
10720+
pub fn add_one(thing) {
10721+
thing + 1
10722+
}
10723+
"#,
10724+
find_position_of("const").select_until(find_position_of("="))
10725+
);
10726+
}
10727+
10728+
10729+
#[test]
10730+
fn annotate_all_top_level_definitions_function() {
10731+
assert_code_action!(
10732+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10733+
r#"
10734+
pub fn add_two(thing) {
10735+
thing + 2
10736+
}
10737+
10738+
pub fn add_one(thing) {
10739+
thing + 1
10740+
}
10741+
"#,
10742+
find_position_of("fn").select_until(find_position_of("("))
10743+
);
10744+
}
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+
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+
}
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)