Skip to content

Commit 7d7a50d

Browse files
committed
Add clone generation tests
1 parent 4b5139e commit 7d7a50d

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,117 @@ impl core::hash::Hash for Foo {
443443
core::mem::discriminant(self).hash(state);
444444
}
445445
}
446+
"#,
447+
)
448+
}
449+
450+
#[test]
451+
fn add_custom_impl_clone_record_struct() {
452+
check_assist(
453+
replace_derive_with_manual_impl,
454+
r#"
455+
//- minicore: clone
456+
#[derive(Clo$0ne)]
457+
struct Foo {
458+
bin: usize,
459+
bar: usize,
460+
}
461+
"#,
462+
r#"
463+
struct Foo {
464+
bin: usize,
465+
bar: usize,
466+
}
467+
468+
impl Clone for Foo {
469+
$0fn clone(&self) -> Self {
470+
Self {
471+
bin: self.bin.clone(),
472+
bar: self.bar.clone(),
473+
}
474+
}
475+
}
476+
"#,
477+
)
478+
}
479+
480+
#[test]
481+
fn add_custom_impl_clone_tuple_struct() {
482+
check_assist(
483+
replace_derive_with_manual_impl,
484+
r#"
485+
//- minicore: clone
486+
#[derive(Clo$0ne)]
487+
struct Foo(usize, usize);
488+
"#,
489+
r#"
490+
struct Foo(usize, usize);
491+
492+
impl Clone for Foo {
493+
$0fn clone(&self) -> Self {
494+
Self(self.0.clone(), self.1.clone())
495+
}
496+
}
497+
"#,
498+
)
499+
}
500+
501+
#[test]
502+
fn add_custom_impl_clone_enum() {
503+
check_assist(
504+
replace_derive_with_manual_impl,
505+
r#"
506+
//- minicore: clone
507+
#[derive(Clo$0ne)]
508+
enum Foo {
509+
Bar,
510+
Baz,
511+
}
512+
"#,
513+
r#"
514+
enum Foo {
515+
Bar,
516+
Baz,
517+
}
518+
519+
impl Clone for Foo {
520+
$0fn clone(&self) -> Self {
521+
match self {
522+
Self::Bar => Self::Bar,
523+
Self::Baz => Self::Baz,
524+
}
525+
}
526+
}
527+
"#,
528+
)
529+
}
530+
531+
#[test]
532+
fn add_custom_impl_clone_tuple_enum() {
533+
check_assist(
534+
replace_derive_with_manual_impl,
535+
r#"
536+
//- minicore: clone
537+
#[derive(Clo$0ne)]
538+
enum Foo {
539+
Bar,
540+
Baz,
541+
}
542+
"#,
543+
r#"
544+
enum Foo {
545+
Bar(String),
546+
Baz,
547+
}
548+
549+
impl Clone for Foo {
550+
$0fn clone(&self) -> Self {
551+
match self {
552+
Self::Bar(arg1) => Self::Bar(arg1.clone()),
553+
Self::Baz => Self::Baz,
554+
}
555+
}
556+
}
446557
"#,
447558
)
448559
}

0 commit comments

Comments
 (0)