rust-analyzer/crates/ra_assists/src/tests/generated.rs

864 lines
13 KiB
Rust
Raw Normal View History

2020-02-07 21:35:34 +00:00
//! Generated file, do not edit by hand, see `xtask/src/codegen`
2019-10-25 11:16:46 +00:00
2020-05-06 08:21:35 +00:00
use super::check_doc_test;
2019-10-25 11:16:46 +00:00
#[test]
fn doctest_add_custom_impl() {
2020-05-06 08:21:35 +00:00
check_doc_test(
"add_custom_impl",
r#####"
#[derive(Deb<|>ug, Display)]
struct S;
"#####,
r#####"
#[derive(Display)]
struct S;
impl Debug for S {
2020-05-17 12:21:24 +00:00
$0
}
"#####,
)
}
2019-10-25 20:38:15 +00:00
#[test]
fn doctest_add_derive() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 20:38:15 +00:00
"add_derive",
r#####"
struct Point {
x: u32,
y: u32,<|>
}
"#####,
r#####"
2020-05-17 12:21:24 +00:00
#[derive($0)]
2019-10-25 20:38:15 +00:00
struct Point {
x: u32,
y: u32,
}
"#####,
)
}
#[test]
fn doctest_add_explicit_type() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 20:38:15 +00:00
"add_explicit_type",
r#####"
fn main() {
let x<|> = 92;
}
"#####,
r#####"
fn main() {
let x: i32 = 92;
}
"#####,
)
2020-03-26 19:59:35 +00:00
}
#[test]
fn doctest_add_from_impl_for_enum() {
check_doc_test(
"add_from_impl_for_enum",
r#####"
enum A { <|>One(u32) }
"#####,
r#####"
enum A { One(u32) }
impl From<u32> for A {
fn from(v: u32) -> Self {
A::One(v)
}
}
"#####,
)
}
2020-03-26 19:59:35 +00:00
#[test]
fn doctest_add_function() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2020-03-26 19:59:35 +00:00
"add_function",
r#####"
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
bar<|>("", baz());
2020-03-26 19:59:35 +00:00
}
"#####,
r#####"
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
bar("", baz());
2020-03-26 19:59:35 +00:00
}
fn bar(arg: &str, baz: Baz) {
2020-05-19 20:25:07 +00:00
${0:todo!()}
2020-03-26 19:59:35 +00:00
}
"#####,
)
2019-10-25 20:38:15 +00:00
}
2019-10-27 09:22:53 +00:00
#[test]
fn doctest_add_hash() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"add_hash",
r#####"
fn main() {
r#"Hello,<|> World!"#;
}
"#####,
r#####"
fn main() {
r##"Hello, World!"##;
}
"#####,
)
}
2019-10-25 20:38:15 +00:00
#[test]
fn doctest_add_impl() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 20:38:15 +00:00
"add_impl",
r#####"
struct Ctx<T: Clone> {
2020-05-17 12:21:24 +00:00
data: T,<|>
2019-10-25 20:38:15 +00:00
}
"#####,
r#####"
struct Ctx<T: Clone> {
2020-05-17 12:21:24 +00:00
data: T,
2019-10-25 20:38:15 +00:00
}
impl<T: Clone> Ctx<T> {
2020-05-17 12:21:24 +00:00
$0
2019-10-25 20:38:15 +00:00
}
"#####,
)
}
#[test]
fn doctest_add_impl_default_members() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 20:38:15 +00:00
"add_impl_default_members",
r#####"
trait Trait {
2019-10-25 20:38:15 +00:00
Type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
2019-10-25 20:38:15 +00:00
Type X = ();
fn foo(&self) {}<|>
}
"#####,
r#####"
trait Trait {
2019-10-25 20:38:15 +00:00
Type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
2019-10-25 20:38:15 +00:00
Type X = ();
fn foo(&self) {}
2020-05-19 23:53:21 +00:00
$0fn bar(&self) {}
2019-10-25 20:38:15 +00:00
}
"#####,
)
}
#[test]
fn doctest_add_impl_missing_members() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 20:38:15 +00:00
"add_impl_missing_members",
r#####"
trait Trait<T> {
2019-10-25 20:38:15 +00:00
Type X;
fn foo(&self) -> T;
2019-10-25 20:38:15 +00:00
fn bar(&self) {}
}
impl Trait<u32> for () {<|>
2019-10-25 20:38:15 +00:00
}
"#####,
r#####"
trait Trait<T> {
2019-10-25 20:38:15 +00:00
Type X;
fn foo(&self) -> T;
2019-10-25 20:38:15 +00:00
fn bar(&self) {}
}
impl Trait<u32> for () {
fn foo(&self) -> u32 {
${0:todo!()}
}
2019-10-25 20:38:15 +00:00
}
"#####,
)
}
#[test]
fn doctest_add_new() {
2020-05-06 08:21:35 +00:00
check_doc_test(
"add_new",
r#####"
struct Ctx<T: Clone> {
data: T,<|>
}
"#####,
r#####"
struct Ctx<T: Clone> {
data: T,
}
impl<T: Clone> Ctx<T> {
2020-05-20 08:17:46 +00:00
fn $0new(data: T) -> Self { Self { data } }
}
"#####,
)
}
2020-05-19 22:07:00 +00:00
#[test]
fn doctest_add_turbo_fish() {
check_doc_test(
"add_turbo_fish",
r#####"
fn make<T>() -> T { todo!() }
fn main() {
let x = make<|>();
}
"#####,
r#####"
fn make<T>() -> T { todo!() }
fn main() {
let x = make::<${0:_}>();
}
"#####,
)
}
2019-10-25 20:38:15 +00:00
#[test]
fn doctest_apply_demorgan() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 20:38:15 +00:00
"apply_demorgan",
r#####"
fn main() {
if x != 4 ||<|> !y {}
}
"#####,
r#####"
fn main() {
if !(x == 4 && y) {}
}
"#####,
)
}
#[test]
fn doctest_auto_import() {
2020-05-06 08:21:35 +00:00
check_doc_test(
"auto_import",
r#####"
fn main() {
let map = HashMap<|>::new();
}
2020-02-06 17:10:25 +00:00
pub mod std { pub mod collections { pub struct HashMap { } } }
"#####,
r#####"
use std::collections::HashMap;
fn main() {
2020-02-06 17:10:25 +00:00
let map = HashMap::new();
}
2020-02-06 17:10:25 +00:00
pub mod std { pub mod collections { pub struct HashMap { } } }
"#####,
)
}
#[test]
fn doctest_change_return_type_to_result() {
check_doc_test(
"change_return_type_to_result",
r#####"
fn foo() -> i32<|> { 42i32 }
"#####,
r#####"
fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
"#####,
)
}
2019-10-26 14:37:04 +00:00
#[test]
fn doctest_change_visibility() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-26 14:37:04 +00:00
"change_visibility",
r#####"
2019-10-26 18:17:39 +00:00
<|>fn frobnicate() {}
2019-10-26 14:37:04 +00:00
"#####,
r#####"
pub(crate) fn frobnicate() {}
"#####,
)
}
2019-10-25 11:16:46 +00:00
#[test]
fn doctest_convert_to_guarded_return() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-25 11:16:46 +00:00
"convert_to_guarded_return",
r#####"
fn main() {
<|>if cond {
foo();
bar();
}
}
"#####,
r#####"
fn main() {
if !cond {
return;
}
foo();
bar();
}
"#####,
)
}
2019-10-26 14:37:04 +00:00
2020-06-03 18:43:57 +00:00
#[test]
fn doctest_extract_struct_from_enum_variant() {
check_doc_test(
"extract_struct_from_enum_variant",
r#####"
enum A { <|>One(u32, u32) }
"#####,
r#####"
struct One(pub u32, pub u32);
enum A { One(One) }
"#####,
)
}
2020-06-26 23:21:43 +00:00
#[test]
fn doctest_extract_variable() {
check_doc_test(
"extract_variable",
r#####"
fn main() {
<|>(1 + 2)<|> * 4;
}
"#####,
r#####"
fn main() {
let $0var_name = (1 + 2);
var_name * 4;
}
"#####,
)
}
2019-10-26 14:37:04 +00:00
#[test]
fn doctest_fill_match_arms() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-26 14:37:04 +00:00
"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 {
2020-05-20 12:00:37 +00:00
$0Action::Move { distance } => {}
Action::Stop => {}
2019-10-26 14:37:04 +00:00
}
}
"#####,
)
}
2019-10-26 16:08:13 +00:00
#[test]
fn doctest_fix_visibility() {
check_doc_test(
"fix_visibility",
r#####"
mod m {
fn frobnicate() {}
}
fn main() {
m::frobnicate<|>() {}
}
"#####,
r#####"
mod m {
2020-05-20 12:13:17 +00:00
$0pub(crate) fn frobnicate() {}
}
fn main() {
m::frobnicate() {}
}
"#####,
)
}
2019-10-26 16:08:13 +00:00
#[test]
fn doctest_flip_binexpr() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-26 16:08:13 +00:00
"flip_binexpr",
r#####"
fn main() {
let _ = 90 +<|> 2;
}
"#####,
r#####"
fn main() {
let _ = 2 + 90;
}
"#####,
)
}
#[test]
fn doctest_flip_comma() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-26 16:08:13 +00:00
"flip_comma",
r#####"
fn main() {
((1, 2),<|> (3, 4));
}
"#####,
r#####"
fn main() {
((3, 4), (1, 2));
}
"#####,
)
}
#[test]
fn doctest_flip_trait_bound() {
2020-05-06 08:21:35 +00:00
check_doc_test(
"flip_trait_bound",
r#####"
fn foo<T: Clone +<|> Copy>() { }
"#####,
r#####"
fn foo<T: Copy + Clone>() { }
"#####,
)
}
2019-10-26 16:08:13 +00:00
#[test]
fn doctest_inline_local_variable() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-26 16:08:13 +00:00
"inline_local_variable",
r#####"
fn main() {
let x<|> = 1 + 2;
x * 4;
}
"#####,
r#####"
fn main() {
(1 + 2) * 4;
}
"#####,
)
}
2019-10-26 16:58:18 +00:00
2020-06-01 13:36:51 +00:00
#[test]
fn doctest_introduce_named_lifetime() {
check_doc_test(
"introduce_named_lifetime",
r#####"
impl Cursor<'_<|>> {
fn node(self) -> &SyntaxNode {
match self {
Cursor::Replace(node) | Cursor::Before(node) => node,
}
}
}
"#####,
r#####"
impl<'a> Cursor<'a> {
fn node(self) -> &SyntaxNode {
match self {
Cursor::Replace(node) | Cursor::Before(node) => node,
}
}
}
"#####,
)
}
2019-11-21 18:51:40 +00:00
#[test]
fn doctest_invert_if() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-11-21 18:51:40 +00:00
"invert_if",
r#####"
fn main() {
2019-11-24 05:14:57 +00:00
if<|> !y { A } else { B }
2019-11-21 18:51:40 +00:00
}
"#####,
r#####"
fn main() {
2019-11-24 05:14:57 +00:00
if y { B } else { A }
2019-11-21 18:51:40 +00:00
}
"#####,
)
}
2019-10-27 09:22:53 +00:00
#[test]
fn doctest_make_raw_string() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"make_raw_string",
r#####"
fn main() {
"Hello,<|> World!";
}
"#####,
r#####"
fn main() {
r#"Hello, World!"#;
}
"#####,
)
}
#[test]
fn doctest_make_usual_string() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"make_usual_string",
r#####"
fn main() {
r#"Hello,<|> "World!""#;
}
"#####,
r#####"
fn main() {
"Hello, \"World!\"";
}
"#####,
)
}
#[test]
fn doctest_merge_imports() {
2020-05-06 08:21:35 +00:00
check_doc_test(
"merge_imports",
r#####"
use std::<|>fmt::Formatter;
use std::io;
"#####,
r#####"
use std::{fmt::Formatter, io};
"#####,
)
}
2019-10-27 08:26:46 +00:00
#[test]
fn doctest_merge_match_arms() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 08:26:46 +00:00
"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() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 08:26:46 +00:00
"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() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 08:26:46 +00:00
"move_bounds_to_where_clause",
r#####"
fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U {
f(x)
}
"#####,
r#####"
fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
f(x)
}
"#####,
)
}
#[test]
fn doctest_move_guard_to_arm_body() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 08:26:46 +00:00
"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() },
_ => (),
}
}
"#####,
)
}
2019-10-27 09:22:53 +00:00
#[test]
fn doctest_remove_dbg() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"remove_dbg",
r#####"
fn main() {
<|>dbg!(92);
}
"#####,
r#####"
fn main() {
92;
}
"#####,
)
}
#[test]
fn doctest_remove_hash() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"remove_hash",
r#####"
fn main() {
r#"Hello,<|> World!"#;
}
"#####,
r#####"
fn main() {
r"Hello, World!";
}
2020-02-19 11:44:20 +00:00
"#####,
)
}
#[test]
fn doctest_remove_mut() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2020-02-19 11:44:20 +00:00
"remove_mut",
r#####"
impl Walrus {
fn feed(&mut<|> self, amount: u32) {}
}
"#####,
r#####"
impl Walrus {
fn feed(&self, amount: u32) {}
}
2019-10-27 09:22:53 +00:00
"#####,
)
}
2020-04-11 18:32:58 +00:00
#[test]
fn doctest_reorder_fields() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2020-04-11 18:32:58 +00:00
"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}
"#####,
)
}
2019-10-27 09:22:53 +00:00
#[test]
fn doctest_replace_if_let_with_match() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"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(),
}
}
"#####,
)
}
2020-03-27 11:12:17 +00:00
#[test]
fn doctest_replace_let_with_if_let() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2020-03-27 11:12:17 +00:00
"replace_let_with_if_let",
r#####"
enum Option<T> { Some(T), None }
fn main(action: Action) {
<|>let x = compute();
}
fn compute() -> Option<i32> { None }
"#####,
r#####"
enum Option<T> { Some(T), None }
fn main(action: Action) {
if let Some(x) = compute() {
}
}
fn compute() -> Option<i32> { None }
"#####,
)
}
2020-02-07 21:35:34 +00:00
#[test]
fn doctest_replace_qualified_name_with_use() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2020-02-07 21:35:34 +00:00
"replace_qualified_name_with_use",
r#####"
fn process(map: std::collections::<|>HashMap<String, String>) {}
"#####,
r#####"
use std::collections::HashMap;
fn process(map: HashMap<String, String>) {}
"#####,
)
}
2020-03-26 09:16:10 +00:00
#[test]
fn doctest_replace_unwrap_with_match() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2020-03-26 09:16:10 +00:00
"replace_unwrap_with_match",
r#####"
enum Result<T, E> { Ok(T), Err(E) }
fn main() {
let x: Result<i32, i32> = Result::Ok(92);
let y = x.<|>unwrap();
}
"#####,
r#####"
enum Result<T, E> { Ok(T), Err(E) }
fn main() {
let x: Result<i32, i32> = Result::Ok(92);
let y = match x {
Ok(a) => a,
2020-05-20 22:01:08 +00:00
$0_ => unreachable!(),
2020-03-26 09:16:10 +00:00
};
}
"#####,
)
}
2019-10-27 09:22:53 +00:00
#[test]
fn doctest_split_import() {
2020-05-06 08:21:35 +00:00
check_doc_test(
2019-10-27 09:22:53 +00:00
"split_import",
r#####"
use std::<|>collections::HashMap;
"#####,
r#####"
use std::{collections::HashMap};
"#####,
)
}
#[test]
fn doctest_unwrap_block() {
2020-05-06 08:21:35 +00:00
check_doc_test(
"unwrap_block",
r#####"
fn foo() {
if true {<|>
println!("foo");
}
}
"#####,
r#####"
fn foo() {
println!("foo");
}
"#####,
)
}