Add clone generation tests

This commit is contained in:
Yoshua Wuyts 2021-08-10 13:20:24 +02:00
parent 4b5139e8a5
commit 7d7a50daf7

View File

@ -443,6 +443,117 @@ impl core::hash::Hash for Foo {
core::mem::discriminant(self).hash(state);
}
}
"#,
)
}
#[test]
fn add_custom_impl_clone_record_struct() {
check_assist(
replace_derive_with_manual_impl,
r#"
//- minicore: clone
#[derive(Clo$0ne)]
struct Foo {
bin: usize,
bar: usize,
}
"#,
r#"
struct Foo {
bin: usize,
bar: usize,
}
impl Clone for Foo {
$0fn clone(&self) -> Self {
Self {
bin: self.bin.clone(),
bar: self.bar.clone(),
}
}
}
"#,
)
}
#[test]
fn add_custom_impl_clone_tuple_struct() {
check_assist(
replace_derive_with_manual_impl,
r#"
//- minicore: clone
#[derive(Clo$0ne)]
struct Foo(usize, usize);
"#,
r#"
struct Foo(usize, usize);
impl Clone for Foo {
$0fn clone(&self) -> Self {
Self(self.0.clone(), self.1.clone())
}
}
"#,
)
}
#[test]
fn add_custom_impl_clone_enum() {
check_assist(
replace_derive_with_manual_impl,
r#"
//- minicore: clone
#[derive(Clo$0ne)]
enum Foo {
Bar,
Baz,
}
"#,
r#"
enum Foo {
Bar,
Baz,
}
impl Clone for Foo {
$0fn clone(&self) -> Self {
match self {
Self::Bar => Self::Bar,
Self::Baz => Self::Baz,
}
}
}
"#,
)
}
#[test]
fn add_custom_impl_clone_tuple_enum() {
check_assist(
replace_derive_with_manual_impl,
r#"
//- minicore: clone
#[derive(Clo$0ne)]
enum Foo {
Bar,
Baz,
}
"#,
r#"
enum Foo {
Bar(String),
Baz,
}
impl Clone for Foo {
$0fn clone(&self) -> Self {
match self {
Self::Bar(arg1) => Self::Bar(arg1.clone()),
Self::Baz => Self::Baz,
}
}
}
"#,
)
}