aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src')
-rw-r--r--crates/assists/src/handlers/extract_function.rs120
1 files changed, 120 insertions, 0 deletions
diff --git a/crates/assists/src/handlers/extract_function.rs b/crates/assists/src/handlers/extract_function.rs
index dfb3da7a5..5d6f5bb26 100644
--- a/crates/assists/src/handlers/extract_function.rs
+++ b/crates/assists/src/handlers/extract_function.rs
@@ -1011,6 +1011,126 @@ fn $0fun_name() {
1011 } 1011 }
1012 1012
1013 #[test] 1013 #[test]
1014 fn no_args_if() {
1015 check_assist(
1016 extract_function,
1017 r#"
1018fn foo() {
1019 $0if true { }$0
1020}"#,
1021 r#"
1022fn foo() {
1023 fun_name();
1024}
1025
1026fn $0fun_name() {
1027 if true { }
1028}"#,
1029 );
1030 }
1031
1032 #[test]
1033 fn no_args_if_else() {
1034 check_assist(
1035 extract_function,
1036 r#"
1037fn foo() -> i32 {
1038 $0if true { 1 } else { 2 }$0
1039}"#,
1040 r#"
1041fn foo() -> i32 {
1042 fun_name()
1043}
1044
1045fn $0fun_name() -> i32 {
1046 if true { 1 } else { 2 }
1047}"#,
1048 );
1049 }
1050
1051 #[test]
1052 fn no_args_if_let_else() {
1053 check_assist(
1054 extract_function,
1055 r#"
1056fn foo() -> i32 {
1057 $0if let true = false { 1 } else { 2 }$0
1058}"#,
1059 r#"
1060fn foo() -> i32 {
1061 fun_name()
1062}
1063
1064fn $0fun_name() -> i32 {
1065 if let true = false { 1 } else { 2 }
1066}"#,
1067 );
1068 }
1069
1070 #[test]
1071 fn no_args_match() {
1072 check_assist(
1073 extract_function,
1074 r#"
1075fn foo() -> i32 {
1076 $0match true {
1077 true => 1,
1078 false => 2,
1079 }$0
1080}"#,
1081 r#"
1082fn foo() -> i32 {
1083 fun_name()
1084}
1085
1086fn $0fun_name() -> i32 {
1087 match true {
1088 true => 1,
1089 false => 2,
1090 }
1091}"#,
1092 );
1093 }
1094
1095 #[test]
1096 fn no_args_while() {
1097 check_assist(
1098 extract_function,
1099 r#"
1100fn foo() {
1101 $0while true { }$0
1102}"#,
1103 r#"
1104fn foo() {
1105 fun_name();
1106}
1107
1108fn $0fun_name() {
1109 while true { }
1110}"#,
1111 );
1112 }
1113
1114 #[test]
1115 fn no_args_for() {
1116 check_assist(
1117 extract_function,
1118 r#"
1119fn foo() {
1120 $0for v in &[0, 1] { }$0
1121}"#,
1122 r#"
1123fn foo() {
1124 fun_name();
1125}
1126
1127fn $0fun_name() {
1128 for v in &[0, 1] { }
1129}"#,
1130 );
1131 }
1132
1133 #[test]
1014 fn no_args_from_loop_unit() { 1134 fn no_args_from_loop_unit() {
1015 check_assist( 1135 check_assist(
1016 extract_function, 1136 extract_function,