diff options
author | Vladyslav Katasonov <[email protected]> | 2021-02-04 23:30:34 +0000 |
---|---|---|
committer | Vladyslav Katasonov <[email protected]> | 2021-02-04 23:30:34 +0000 |
commit | 271c1cb01325ac252b5153c3729462a4d96a0e0a (patch) | |
tree | 253108c1678315dc994f2995ad3c5f24334e8c1c /crates | |
parent | 4dc2a42500b52001299ef861d5105d8a8249ecd8 (diff) |
add tests for extracting if/match/while/for exprs
Diffstat (limited to 'crates')
-rw-r--r-- | crates/assists/src/handlers/extract_function.rs | 120 |
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#" | ||
1018 | fn foo() { | ||
1019 | $0if true { }$0 | ||
1020 | }"#, | ||
1021 | r#" | ||
1022 | fn foo() { | ||
1023 | fun_name(); | ||
1024 | } | ||
1025 | |||
1026 | fn $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#" | ||
1037 | fn foo() -> i32 { | ||
1038 | $0if true { 1 } else { 2 }$0 | ||
1039 | }"#, | ||
1040 | r#" | ||
1041 | fn foo() -> i32 { | ||
1042 | fun_name() | ||
1043 | } | ||
1044 | |||
1045 | fn $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#" | ||
1056 | fn foo() -> i32 { | ||
1057 | $0if let true = false { 1 } else { 2 }$0 | ||
1058 | }"#, | ||
1059 | r#" | ||
1060 | fn foo() -> i32 { | ||
1061 | fun_name() | ||
1062 | } | ||
1063 | |||
1064 | fn $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#" | ||
1075 | fn foo() -> i32 { | ||
1076 | $0match true { | ||
1077 | true => 1, | ||
1078 | false => 2, | ||
1079 | }$0 | ||
1080 | }"#, | ||
1081 | r#" | ||
1082 | fn foo() -> i32 { | ||
1083 | fun_name() | ||
1084 | } | ||
1085 | |||
1086 | fn $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#" | ||
1100 | fn foo() { | ||
1101 | $0while true { }$0 | ||
1102 | }"#, | ||
1103 | r#" | ||
1104 | fn foo() { | ||
1105 | fun_name(); | ||
1106 | } | ||
1107 | |||
1108 | fn $0fun_name() { | ||
1109 | while true { } | ||
1110 | }"#, | ||
1111 | ); | ||
1112 | } | ||
1113 | |||
1114 | #[test] | ||
1115 | fn no_args_for() { | ||
1116 | check_assist( | ||
1117 | extract_function, | ||
1118 | r#" | ||
1119 | fn foo() { | ||
1120 | $0for v in &[0, 1] { }$0 | ||
1121 | }"#, | ||
1122 | r#" | ||
1123 | fn foo() { | ||
1124 | fun_name(); | ||
1125 | } | ||
1126 | |||
1127 | fn $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, |