Skip to content

Commit ed0f664

Browse files
committed
chore: write tests + snapshots
1 parent 36c51a6 commit ed0f664

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";
@@ -10637,3 +10638,58 @@ fn wibble(f: fn() -> Float) -> Float { f() }
1063710638
.select_until(find_position_of("}"))
1063810639
);
1063910640
}
10641+
10642+
#[test]
10643+
fn annotate_all_top_level_definitions_dont_affect_local_vars() {
10644+
assert_code_action!(
10645+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10646+
r#"
10647+
pub const answer = 42
10648+
10649+
pub fn add_two(thing) {
10650+
thing + 2
10651+
10652+
pub fn add_one(thing) {
10653+
let result = thing + 1
10654+
result
10655+
}
10656+
"#,
10657+
find_position_of("fn").select_until(find_position_of("("));
10658+
}
10659+
10660+
#[test]
10661+
fn annotate_all_top_level_definitions_constant() {
10662+
assert_code_action!(
10663+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10664+
r#"
10665+
pub const answer = 42
10666+
10667+
pub fn add_two(thing) {
10668+
thing + 2
10669+
}
10670+
10671+
pub fn add_one(thing) {
10672+
thing + 1
10673+
}
10674+
"#,
10675+
find_position_of("const").select_until(find_position_of("="))
10676+
);
10677+
}
10678+
10679+
10680+
#[test]
10681+
fn annotate_all_top_level_definitions_function() {
10682+
assert_code_action!(
10683+
ANNOTATE_TOP_LEVEL_TYPE_DEFINITIONS,
10684+
r#"
10685+
pub fn add_two(thing) {
10686+
thing + 2
10687+
}
10688+
10689+
pub fn add_one(thing) {
10690+
thing + 1
10691+
}
10692+
"#,
10693+
find_position_of("fn").select_until(find_position_of("("))
10694+
);
10695+
}
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)