From d308ff910b18719fabaeb9df7bc5fc0afbd0a194 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 10:18:12 +0200 Subject: Merge doc_tests and tests --- crates/ra_assists/src/doc_tests.rs | 39 -- crates/ra_assists/src/doc_tests/generated.rs | 749 --------------------------- crates/ra_assists/src/lib.rs | 2 - crates/ra_assists/src/tests.rs | 28 + crates/ra_assists/src/tests/generated.rs | 749 +++++++++++++++++++++++++++ 5 files changed, 777 insertions(+), 790 deletions(-) delete mode 100644 crates/ra_assists/src/doc_tests.rs delete mode 100644 crates/ra_assists/src/doc_tests/generated.rs create mode 100644 crates/ra_assists/src/tests/generated.rs diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs deleted file mode 100644 index 5eabb33d0..000000000 --- a/crates/ra_assists/src/doc_tests.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Each assist definition has a special comment, which specifies docs and -//! example. -//! -//! We collect all the example and write the as tests in this module. - -mod generated; - -use ra_db::FileRange; -use test_utils::{assert_eq_text, extract_range_or_offset}; - -use crate::resolved_assists; - -fn check(assist_id: &str, before: &str, after: &str) { - let (selection, before) = extract_range_or_offset(before); - let (db, file_id) = crate::tests::with_single_file(&before); - let frange = FileRange { file_id, range: selection.into() }; - - let assist = resolved_assists(&db, frange) - .into_iter() - .find(|assist| assist.label.id.0 == assist_id) - .unwrap_or_else(|| { - panic!( - "\n\nAssist is not applicable: {}\nAvailable assists: {}", - assist_id, - resolved_assists(&db, frange) - .into_iter() - .map(|assist| assist.label.id.0) - .collect::>() - .join(", ") - ) - }); - - let actual = { - let mut actual = before.clone(); - assist.action.edit.apply(&mut actual); - actual - }; - assert_eq_text!(after, &actual); -} diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs deleted file mode 100644 index 6696cc832..000000000 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ /dev/null @@ -1,749 +0,0 @@ -//! Generated file, do not edit by hand, see `xtask/src/codegen` - -use super::check; - -#[test] -fn doctest_add_custom_impl() { - check( - "add_custom_impl", - r#####" -#[derive(Deb<|>ug, Display)] -struct S; -"#####, - r#####" -#[derive(Display)] -struct S; - -impl Debug for S { - -} -"#####, - ) -} - -#[test] -fn doctest_add_derive() { - check( - "add_derive", - r#####" -struct Point { - x: u32, - y: u32,<|> -} -"#####, - r#####" -#[derive()] -struct Point { - x: u32, - y: u32, -} -"#####, - ) -} - -#[test] -fn doctest_add_explicit_type() { - check( - "add_explicit_type", - r#####" -fn main() { - let x<|> = 92; -} -"#####, - r#####" -fn main() { - let x: i32 = 92; -} -"#####, - ) -} - -#[test] -fn doctest_add_function() { - check( - "add_function", - r#####" -struct Baz; -fn baz() -> Baz { Baz } -fn foo() { - bar<|>("", baz()); -} - -"#####, - r#####" -struct Baz; -fn baz() -> Baz { Baz } -fn foo() { - bar("", baz()); -} - -fn bar(arg: &str, baz: Baz) { - todo!() -} - -"#####, - ) -} - -#[test] -fn doctest_add_hash() { - check( - "add_hash", - r#####" -fn main() { - r#"Hello,<|> World!"#; -} -"#####, - r#####" -fn main() { - r##"Hello, World!"##; -} -"#####, - ) -} - -#[test] -fn doctest_add_impl() { - check( - "add_impl", - r#####" -struct Ctx { - data: T,<|> -} -"#####, - r#####" -struct Ctx { - data: T, -} - -impl Ctx { - -} -"#####, - ) -} - -#[test] -fn doctest_add_impl_default_members() { - check( - "add_impl_default_members", - r#####" -trait Trait { - Type X; - fn foo(&self); - fn bar(&self) {} -} - -impl Trait for () { - Type X = (); - fn foo(&self) {}<|> - -} -"#####, - r#####" -trait Trait { - Type X; - fn foo(&self); - fn bar(&self) {} -} - -impl Trait for () { - Type X = (); - fn foo(&self) {} - fn bar(&self) {} - -} -"#####, - ) -} - -#[test] -fn doctest_add_impl_missing_members() { - check( - "add_impl_missing_members", - r#####" -trait Trait { - Type X; - fn foo(&self) -> T; - fn bar(&self) {} -} - -impl Trait for () {<|> - -} -"#####, - r#####" -trait Trait { - Type X; - fn foo(&self) -> T; - fn bar(&self) {} -} - -impl Trait for () { - fn foo(&self) -> u32 { - todo!() - } - -} -"#####, - ) -} - -#[test] -fn doctest_add_new() { - check( - "add_new", - r#####" -struct Ctx { - data: T,<|> -} -"#####, - r#####" -struct Ctx { - data: T, -} - -impl Ctx { - fn new(data: T) -> Self { Self { data } } -} - -"#####, - ) -} - -#[test] -fn doctest_apply_demorgan() { - check( - "apply_demorgan", - r#####" -fn main() { - if x != 4 ||<|> !y {} -} -"#####, - r#####" -fn main() { - if !(x == 4 && y) {} -} -"#####, - ) -} - -#[test] -fn doctest_auto_import() { - check( - "auto_import", - r#####" -fn main() { - let map = HashMap<|>::new(); -} -pub mod std { pub mod collections { pub struct HashMap { } } } -"#####, - r#####" -use std::collections::HashMap; - -fn main() { - let map = HashMap::new(); -} -pub mod std { pub mod collections { pub struct HashMap { } } } -"#####, - ) -} - -#[test] -fn doctest_change_visibility() { - check( - "change_visibility", - r#####" -<|>fn frobnicate() {} -"#####, - r#####" -pub(crate) fn frobnicate() {} -"#####, - ) -} - -#[test] -fn doctest_convert_to_guarded_return() { - check( - "convert_to_guarded_return", - r#####" -fn main() { - <|>if cond { - foo(); - bar(); - } -} -"#####, - r#####" -fn main() { - if !cond { - return; - } - foo(); - bar(); -} -"#####, - ) -} - -#[test] -fn doctest_fill_match_arms() { - check( - "fill_match_arms", - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - <|> - } -} -"#####, - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move { distance } => {} - Action::Stop => {} - } -} -"#####, - ) -} - -#[test] -fn doctest_flip_binexpr() { - check( - "flip_binexpr", - r#####" -fn main() { - let _ = 90 +<|> 2; -} -"#####, - r#####" -fn main() { - let _ = 2 + 90; -} -"#####, - ) -} - -#[test] -fn doctest_flip_comma() { - check( - "flip_comma", - r#####" -fn main() { - ((1, 2),<|> (3, 4)); -} -"#####, - r#####" -fn main() { - ((3, 4), (1, 2)); -} -"#####, - ) -} - -#[test] -fn doctest_flip_trait_bound() { - check( - "flip_trait_bound", - r#####" -fn foo Copy>() { } -"#####, - r#####" -fn foo() { } -"#####, - ) -} - -#[test] -fn doctest_inline_local_variable() { - check( - "inline_local_variable", - r#####" -fn main() { - let x<|> = 1 + 2; - x * 4; -} -"#####, - r#####" -fn main() { - (1 + 2) * 4; -} -"#####, - ) -} - -#[test] -fn doctest_introduce_variable() { - check( - "introduce_variable", - r#####" -fn main() { - <|>(1 + 2)<|> * 4; -} -"#####, - r#####" -fn main() { - let var_name = (1 + 2); - var_name * 4; -} -"#####, - ) -} - -#[test] -fn doctest_invert_if() { - check( - "invert_if", - r#####" -fn main() { - if<|> !y { A } else { B } -} -"#####, - r#####" -fn main() { - if y { B } else { A } -} -"#####, - ) -} - -#[test] -fn doctest_make_raw_string() { - check( - "make_raw_string", - r#####" -fn main() { - "Hello,<|> World!"; -} -"#####, - r#####" -fn main() { - r#"Hello, World!"#; -} -"#####, - ) -} - -#[test] -fn doctest_make_usual_string() { - check( - "make_usual_string", - r#####" -fn main() { - r#"Hello,<|> "World!""#; -} -"#####, - r#####" -fn main() { - "Hello, \"World!\""; -} -"#####, - ) -} - -#[test] -fn doctest_merge_imports() { - check( - "merge_imports", - r#####" -use std::<|>fmt::Formatter; -use std::io; -"#####, - r#####" -use std::{fmt::Formatter, io}; -"#####, - ) -} - -#[test] -fn doctest_merge_match_arms() { - check( - "merge_match_arms", - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - <|>Action::Move(..) => foo(), - Action::Stop => foo(), - } -} -"#####, - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move(..) | Action::Stop => foo(), - } -} -"#####, - ) -} - -#[test] -fn doctest_move_arm_cond_to_match_guard() { - check( - "move_arm_cond_to_match_guard", - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move { distance } => <|>if distance > 10 { foo() }, - _ => (), - } -} -"#####, - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move { distance } if distance > 10 => foo(), - _ => (), - } -} -"#####, - ) -} - -#[test] -fn doctest_move_bounds_to_where_clause() { - check( - "move_bounds_to_where_clause", - r#####" -fn applyF: FnOnce(T) -> U>(f: F, x: T) -> U { - f(x) -} -"#####, - r#####" -fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { - f(x) -} -"#####, - ) -} - -#[test] -fn doctest_move_guard_to_arm_body() { - check( - "move_guard_to_arm_body", - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move { distance } <|>if distance > 10 => foo(), - _ => (), - } -} -"#####, - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move { distance } => if distance > 10 { foo() }, - _ => (), - } -} -"#####, - ) -} - -#[test] -fn doctest_remove_dbg() { - check( - "remove_dbg", - r#####" -fn main() { - <|>dbg!(92); -} -"#####, - r#####" -fn main() { - 92; -} -"#####, - ) -} - -#[test] -fn doctest_remove_hash() { - check( - "remove_hash", - r#####" -fn main() { - r#"Hello,<|> World!"#; -} -"#####, - r#####" -fn main() { - r"Hello, World!"; -} -"#####, - ) -} - -#[test] -fn doctest_remove_mut() { - check( - "remove_mut", - r#####" -impl Walrus { - fn feed(&mut<|> self, amount: u32) {} -} -"#####, - r#####" -impl Walrus { - fn feed(&self, amount: u32) {} -} -"#####, - ) -} - -#[test] -fn doctest_reorder_fields() { - check( - "reorder_fields", - r#####" -struct Foo {foo: i32, bar: i32}; -const test: Foo = <|>Foo {bar: 0, foo: 1} -"#####, - r#####" -struct Foo {foo: i32, bar: i32}; -const test: Foo = Foo {foo: 1, bar: 0} -"#####, - ) -} - -#[test] -fn doctest_replace_if_let_with_match() { - check( - "replace_if_let_with_match", - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - <|>if let Action::Move { distance } = action { - foo(distance) - } else { - bar() - } -} -"#####, - r#####" -enum Action { Move { distance: u32 }, Stop } - -fn handle(action: Action) { - match action { - Action::Move { distance } => foo(distance), - _ => bar(), - } -} -"#####, - ) -} - -#[test] -fn doctest_replace_let_with_if_let() { - check( - "replace_let_with_if_let", - r#####" -enum Option { Some(T), None } - -fn main(action: Action) { - <|>let x = compute(); -} - -fn compute() -> Option { None } -"#####, - r#####" -enum Option { Some(T), None } - -fn main(action: Action) { - if let Some(x) = compute() { - } -} - -fn compute() -> Option { None } -"#####, - ) -} - -#[test] -fn doctest_replace_qualified_name_with_use() { - check( - "replace_qualified_name_with_use", - r#####" -fn process(map: std::collections::<|>HashMap) {} -"#####, - r#####" -use std::collections::HashMap; - -fn process(map: HashMap) {} -"#####, - ) -} - -#[test] -fn doctest_replace_unwrap_with_match() { - check( - "replace_unwrap_with_match", - r#####" -enum Result { Ok(T), Err(E) } -fn main() { - let x: Result = Result::Ok(92); - let y = x.<|>unwrap(); -} -"#####, - r#####" -enum Result { Ok(T), Err(E) } -fn main() { - let x: Result = Result::Ok(92); - let y = match x { - Ok(a) => a, - _ => unreachable!(), - }; -} -"#####, - ) -} - -#[test] -fn doctest_split_import() { - check( - "split_import", - r#####" -use std::<|>collections::HashMap; -"#####, - r#####" -use std::{collections::HashMap}; -"#####, - ) -} - -#[test] -fn doctest_unwrap_block() { - check( - "unwrap_block", - r#####" -fn foo() { - if true {<|> - println!("foo"); - } -} -"#####, - r#####" -fn foo() { - println!("foo"); -} -"#####, - ) -} diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index b84d60c77..b794b021d 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -13,8 +13,6 @@ macro_rules! eprintln { mod assist_ctx; mod marks; #[cfg(test)] -mod doc_tests; -#[cfg(test)] mod tests; pub mod utils; pub mod ast_transform; diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index ca3096a43..97744904a 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -34,6 +34,34 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { check(assist, ra_fixture, ExpectedResult::NotApplicable); } +fn check_doc_test(assist_id: &str, before: &str, after: &str) { + let (selection, before) = extract_range_or_offset(before); + let (db, file_id) = crate::tests::with_single_file(&before); + let frange = FileRange { file_id, range: selection.into() }; + + let assist = resolved_assists(&db, frange) + .into_iter() + .find(|assist| assist.label.id.0 == assist_id) + .unwrap_or_else(|| { + panic!( + "\n\nAssist is not applicable: {}\nAvailable assists: {}", + assist_id, + resolved_assists(&db, frange) + .into_iter() + .map(|assist| assist.label.id.0) + .collect::>() + .join(", ") + ) + }); + + let actual = { + let mut actual = before.clone(); + assist.action.edit.apply(&mut actual); + actual + }; + assert_eq_text!(after, &actual); +} + enum ExpectedResult<'a> { NotApplicable, After(&'a str), diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs new file mode 100644 index 000000000..6696cc832 --- /dev/null +++ b/crates/ra_assists/src/tests/generated.rs @@ -0,0 +1,749 @@ +//! Generated file, do not edit by hand, see `xtask/src/codegen` + +use super::check; + +#[test] +fn doctest_add_custom_impl() { + check( + "add_custom_impl", + r#####" +#[derive(Deb<|>ug, Display)] +struct S; +"#####, + r#####" +#[derive(Display)] +struct S; + +impl Debug for S { + +} +"#####, + ) +} + +#[test] +fn doctest_add_derive() { + check( + "add_derive", + r#####" +struct Point { + x: u32, + y: u32,<|> +} +"#####, + r#####" +#[derive()] +struct Point { + x: u32, + y: u32, +} +"#####, + ) +} + +#[test] +fn doctest_add_explicit_type() { + check( + "add_explicit_type", + r#####" +fn main() { + let x<|> = 92; +} +"#####, + r#####" +fn main() { + let x: i32 = 92; +} +"#####, + ) +} + +#[test] +fn doctest_add_function() { + check( + "add_function", + r#####" +struct Baz; +fn baz() -> Baz { Baz } +fn foo() { + bar<|>("", baz()); +} + +"#####, + r#####" +struct Baz; +fn baz() -> Baz { Baz } +fn foo() { + bar("", baz()); +} + +fn bar(arg: &str, baz: Baz) { + todo!() +} + +"#####, + ) +} + +#[test] +fn doctest_add_hash() { + check( + "add_hash", + r#####" +fn main() { + r#"Hello,<|> World!"#; +} +"#####, + r#####" +fn main() { + r##"Hello, World!"##; +} +"#####, + ) +} + +#[test] +fn doctest_add_impl() { + check( + "add_impl", + r#####" +struct Ctx { + data: T,<|> +} +"#####, + r#####" +struct Ctx { + data: T, +} + +impl Ctx { + +} +"#####, + ) +} + +#[test] +fn doctest_add_impl_default_members() { + check( + "add_impl_default_members", + r#####" +trait Trait { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl Trait for () { + Type X = (); + fn foo(&self) {}<|> + +} +"#####, + r#####" +trait Trait { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl Trait for () { + Type X = (); + fn foo(&self) {} + fn bar(&self) {} + +} +"#####, + ) +} + +#[test] +fn doctest_add_impl_missing_members() { + check( + "add_impl_missing_members", + r#####" +trait Trait { + Type X; + fn foo(&self) -> T; + fn bar(&self) {} +} + +impl Trait for () {<|> + +} +"#####, + r#####" +trait Trait { + Type X; + fn foo(&self) -> T; + fn bar(&self) {} +} + +impl Trait for () { + fn foo(&self) -> u32 { + todo!() + } + +} +"#####, + ) +} + +#[test] +fn doctest_add_new() { + check( + "add_new", + r#####" +struct Ctx { + data: T,<|> +} +"#####, + r#####" +struct Ctx { + data: T, +} + +impl Ctx { + fn new(data: T) -> Self { Self { data } } +} + +"#####, + ) +} + +#[test] +fn doctest_apply_demorgan() { + check( + "apply_demorgan", + r#####" +fn main() { + if x != 4 ||<|> !y {} +} +"#####, + r#####" +fn main() { + if !(x == 4 && y) {} +} +"#####, + ) +} + +#[test] +fn doctest_auto_import() { + check( + "auto_import", + r#####" +fn main() { + let map = HashMap<|>::new(); +} +pub mod std { pub mod collections { pub struct HashMap { } } } +"#####, + r#####" +use std::collections::HashMap; + +fn main() { + let map = HashMap::new(); +} +pub mod std { pub mod collections { pub struct HashMap { } } } +"#####, + ) +} + +#[test] +fn doctest_change_visibility() { + check( + "change_visibility", + r#####" +<|>fn frobnicate() {} +"#####, + r#####" +pub(crate) fn frobnicate() {} +"#####, + ) +} + +#[test] +fn doctest_convert_to_guarded_return() { + check( + "convert_to_guarded_return", + r#####" +fn main() { + <|>if cond { + foo(); + bar(); + } +} +"#####, + r#####" +fn main() { + if !cond { + return; + } + foo(); + bar(); +} +"#####, + ) +} + +#[test] +fn doctest_fill_match_arms() { + check( + "fill_match_arms", + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + <|> + } +} +"#####, + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => {} + Action::Stop => {} + } +} +"#####, + ) +} + +#[test] +fn doctest_flip_binexpr() { + check( + "flip_binexpr", + r#####" +fn main() { + let _ = 90 +<|> 2; +} +"#####, + r#####" +fn main() { + let _ = 2 + 90; +} +"#####, + ) +} + +#[test] +fn doctest_flip_comma() { + check( + "flip_comma", + r#####" +fn main() { + ((1, 2),<|> (3, 4)); +} +"#####, + r#####" +fn main() { + ((3, 4), (1, 2)); +} +"#####, + ) +} + +#[test] +fn doctest_flip_trait_bound() { + check( + "flip_trait_bound", + r#####" +fn foo Copy>() { } +"#####, + r#####" +fn foo() { } +"#####, + ) +} + +#[test] +fn doctest_inline_local_variable() { + check( + "inline_local_variable", + r#####" +fn main() { + let x<|> = 1 + 2; + x * 4; +} +"#####, + r#####" +fn main() { + (1 + 2) * 4; +} +"#####, + ) +} + +#[test] +fn doctest_introduce_variable() { + check( + "introduce_variable", + r#####" +fn main() { + <|>(1 + 2)<|> * 4; +} +"#####, + r#####" +fn main() { + let var_name = (1 + 2); + var_name * 4; +} +"#####, + ) +} + +#[test] +fn doctest_invert_if() { + check( + "invert_if", + r#####" +fn main() { + if<|> !y { A } else { B } +} +"#####, + r#####" +fn main() { + if y { B } else { A } +} +"#####, + ) +} + +#[test] +fn doctest_make_raw_string() { + check( + "make_raw_string", + r#####" +fn main() { + "Hello,<|> World!"; +} +"#####, + r#####" +fn main() { + r#"Hello, World!"#; +} +"#####, + ) +} + +#[test] +fn doctest_make_usual_string() { + check( + "make_usual_string", + r#####" +fn main() { + r#"Hello,<|> "World!""#; +} +"#####, + r#####" +fn main() { + "Hello, \"World!\""; +} +"#####, + ) +} + +#[test] +fn doctest_merge_imports() { + check( + "merge_imports", + r#####" +use std::<|>fmt::Formatter; +use std::io; +"#####, + r#####" +use std::{fmt::Formatter, io}; +"#####, + ) +} + +#[test] +fn doctest_merge_match_arms() { + check( + "merge_match_arms", + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + <|>Action::Move(..) => foo(), + Action::Stop => foo(), + } +} +"#####, + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move(..) | Action::Stop => foo(), + } +} +"#####, + ) +} + +#[test] +fn doctest_move_arm_cond_to_match_guard() { + check( + "move_arm_cond_to_match_guard", + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => <|>if distance > 10 { foo() }, + _ => (), + } +} +"#####, + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } if distance > 10 => foo(), + _ => (), + } +} +"#####, + ) +} + +#[test] +fn doctest_move_bounds_to_where_clause() { + check( + "move_bounds_to_where_clause", + r#####" +fn applyF: FnOnce(T) -> U>(f: F, x: T) -> U { + f(x) +} +"#####, + r#####" +fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { + f(x) +} +"#####, + ) +} + +#[test] +fn doctest_move_guard_to_arm_body() { + check( + "move_guard_to_arm_body", + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } <|>if distance > 10 => foo(), + _ => (), + } +} +"#####, + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => if distance > 10 { foo() }, + _ => (), + } +} +"#####, + ) +} + +#[test] +fn doctest_remove_dbg() { + check( + "remove_dbg", + r#####" +fn main() { + <|>dbg!(92); +} +"#####, + r#####" +fn main() { + 92; +} +"#####, + ) +} + +#[test] +fn doctest_remove_hash() { + check( + "remove_hash", + r#####" +fn main() { + r#"Hello,<|> World!"#; +} +"#####, + r#####" +fn main() { + r"Hello, World!"; +} +"#####, + ) +} + +#[test] +fn doctest_remove_mut() { + check( + "remove_mut", + r#####" +impl Walrus { + fn feed(&mut<|> self, amount: u32) {} +} +"#####, + r#####" +impl Walrus { + fn feed(&self, amount: u32) {} +} +"#####, + ) +} + +#[test] +fn doctest_reorder_fields() { + check( + "reorder_fields", + r#####" +struct Foo {foo: i32, bar: i32}; +const test: Foo = <|>Foo {bar: 0, foo: 1} +"#####, + r#####" +struct Foo {foo: i32, bar: i32}; +const test: Foo = Foo {foo: 1, bar: 0} +"#####, + ) +} + +#[test] +fn doctest_replace_if_let_with_match() { + check( + "replace_if_let_with_match", + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + <|>if let Action::Move { distance } = action { + foo(distance) + } else { + bar() + } +} +"#####, + r#####" +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => foo(distance), + _ => bar(), + } +} +"#####, + ) +} + +#[test] +fn doctest_replace_let_with_if_let() { + check( + "replace_let_with_if_let", + r#####" +enum Option { Some(T), None } + +fn main(action: Action) { + <|>let x = compute(); +} + +fn compute() -> Option { None } +"#####, + r#####" +enum Option { Some(T), None } + +fn main(action: Action) { + if let Some(x) = compute() { + } +} + +fn compute() -> Option { None } +"#####, + ) +} + +#[test] +fn doctest_replace_qualified_name_with_use() { + check( + "replace_qualified_name_with_use", + r#####" +fn process(map: std::collections::<|>HashMap) {} +"#####, + r#####" +use std::collections::HashMap; + +fn process(map: HashMap) {} +"#####, + ) +} + +#[test] +fn doctest_replace_unwrap_with_match() { + check( + "replace_unwrap_with_match", + r#####" +enum Result { Ok(T), Err(E) } +fn main() { + let x: Result = Result::Ok(92); + let y = x.<|>unwrap(); +} +"#####, + r#####" +enum Result { Ok(T), Err(E) } +fn main() { + let x: Result = Result::Ok(92); + let y = match x { + Ok(a) => a, + _ => unreachable!(), + }; +} +"#####, + ) +} + +#[test] +fn doctest_split_import() { + check( + "split_import", + r#####" +use std::<|>collections::HashMap; +"#####, + r#####" +use std::{collections::HashMap}; +"#####, + ) +} + +#[test] +fn doctest_unwrap_block() { + check( + "unwrap_block", + r#####" +fn foo() { + if true {<|> + println!("foo"); + } +} +"#####, + r#####" +fn foo() { + println!("foo"); +} +"#####, + ) +} -- cgit v1.2.3