Skip to content

Commit 62c2002

Browse files
theotherphilmatklad
authored andcommitted
Add test that ok-wrapping handles type aliases
1 parent d025016 commit 62c2002

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

crates/ra_ide_api/src/diagnostics.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,44 @@ fn div(x: i32, y: i32) -> Result<i32, String> {
281281
check_apply_diagnostic_fix_for_target_file("/main.rs", before, after);
282282
}
283283

284+
#[test]
285+
fn test_wrap_return_type_handles_type_aliases() {
286+
let before = r#"
287+
//- /main.rs
288+
use std::{string::String, result::Result::{self, Ok, Err}};
289+
290+
type MyResult<T> = Result<T, String>;
291+
292+
fn div(x: i32, y: i32) -> MyResult<i32> {
293+
if y == 0 {
294+
return Err("div by zero".into());
295+
}
296+
x / y
297+
}
298+
299+
//- /std/lib.rs
300+
pub mod string {
301+
pub struct String { }
302+
}
303+
pub mod result {
304+
pub enum Result<T, E> { Ok(T), Err(E) }
305+
}
306+
"#;
307+
// The formatting here is a bit odd due to how the parse_fixture function works in test_utils -
308+
// it strips empty lines and leading whitespace. The important part of this test is that the final
309+
// `x / y` expr is now wrapped in `Ok(..)`
310+
let after = r#"use std::{string::String, result::Result::{self, Ok, Err}};
311+
type MyResult<T> = Result<T, String>;
312+
fn div(x: i32, y: i32) -> MyResult<i32> {
313+
if y == 0 {
314+
return Err("div by zero".into());
315+
}
316+
Ok(x / y)
317+
}
318+
"#;
319+
check_apply_diagnostic_fix_for_target_file("/main.rs", before, after);
320+
}
321+
284322
#[test]
285323
fn test_wrap_return_type_not_applicable() {
286324
let content = r#"

0 commit comments

Comments
 (0)