]> git.lizzy.rs Git - rust.git/commitdiff
Add clone generation tests
authorYoshua Wuyts <yoshuawuyts@gmail.com>
Tue, 10 Aug 2021 11:20:24 +0000 (13:20 +0200)
committerYoshua Wuyts <yoshuawuyts@gmail.com>
Tue, 10 Aug 2021 11:20:24 +0000 (13:20 +0200)
crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

index bd0b2028a1a00d1dcf78b96f6025cb801f9ed67e..4281e334959734c99be193b7b4733c80822fc2b2 100644 (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,
+        }
+    }
+}
 "#,
         )
     }