add test for method generation assist
@@ -1380,6 +1380,129 @@ fn foo() {
async fn bar(arg: i32) ${0:-> ()} {
todo!()
}
+",
+ )
+ }
+
+ #[test]
+ fn create_method() {
+ check_assist(
+ generate_method,
+ r"
+struct S;
+
+fn foo() {
+ S.bar$0();
+}
+
+",
+ r"
+struct S;
+
+fn foo() {
+ S.bar();
+}
+impl S {
+
+
+fn bar(&self) ${0:-> ()} {
+ todo!()
+}
+}
+
+",
+ )
+ }
+
+ #[test]
+ fn create_method_within_an_impl() {
+ check_assist(
+ generate_method,
+ r"
+struct S;
+
+fn foo() {
+ S.bar$0();
+}
+impl S {}
+
+",
+ r"
+struct S;
+
+fn foo() {
+ S.bar();
+}
+impl S {
+ fn bar(&self) ${0:-> ()} {
+ todo!()
+ }
+}
+
+",
+ )
+ }
+
+ #[test]
+ fn create_method_from_different_module() {
+ check_assist(
+ generate_method,
+ r"
+mod s {
+ pub struct S;
+}
+fn foo() {
+ s::S.bar$0();
+}
+
+",
+ r"
+mod s {
+ pub struct S;
+impl S {
+
+
+ pub(crate) fn bar(&self) ${0:-> ()} {
+ todo!()
+ }
+}
+}
+fn foo() {
+ s::S.bar();
+}
+
+",
+ )
+ }
+
+ #[test]
+ fn create_method_from_descendant_module() {
+ check_assist(
+ generate_method,
+ r"
+struct S;
+mod s {
+ fn foo() {
+ super::S.bar$0();
+ }
+}
+
+",
+ r"
+struct S;
+mod s {
+ fn foo() {
+ super::S.bar();
+ }
+}
+impl S {
+
+
+fn bar(&self) ${0:-> ()} {
+ todo!()
+}
+}
+
",
)
}
