diff options
author | Aleksey Kladov <[email protected]> | 2020-04-24 00:25:54 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-24 00:26:27 +0100 |
commit | 4b8e9d5483005844e711e2f6191274c3c6ae1c4a (patch) | |
tree | e08cdee722389ccbb59749ff5f629ad6265e4208 /crates/ra_ide/src/completion/presentation.rs | |
parent | 174952e89b891b20ea580f37e34389467fb9e23c (diff) |
Move tests to where they belong
Diffstat (limited to 'crates/ra_ide/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index ab43d2a0a..ae15f91de 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -1070,4 +1070,235 @@ mod tests { | |||
1070 | "### | 1070 | "### |
1071 | ); | 1071 | ); |
1072 | } | 1072 | } |
1073 | |||
1074 | #[test] | ||
1075 | fn test_struct_field_completion_in_func_call() { | ||
1076 | assert_debug_snapshot!( | ||
1077 | do_reference_completion( | ||
1078 | r" | ||
1079 | struct A { another_field: i64, the_field: u32, my_string: String } | ||
1080 | fn test(my_param: u32) -> u32 { my_param } | ||
1081 | fn foo(a: A) { | ||
1082 | test(a.<|>) | ||
1083 | } | ||
1084 | ", | ||
1085 | ), | ||
1086 | @r###" | ||
1087 | [ | ||
1088 | CompletionItem { | ||
1089 | label: "another_field", | ||
1090 | source_range: [201; 201), | ||
1091 | delete: [201; 201), | ||
1092 | insert: "another_field", | ||
1093 | kind: Field, | ||
1094 | detail: "i64", | ||
1095 | }, | ||
1096 | CompletionItem { | ||
1097 | label: "my_string", | ||
1098 | source_range: [201; 201), | ||
1099 | delete: [201; 201), | ||
1100 | insert: "my_string", | ||
1101 | kind: Field, | ||
1102 | detail: "{unknown}", | ||
1103 | }, | ||
1104 | CompletionItem { | ||
1105 | label: "the_field", | ||
1106 | source_range: [201; 201), | ||
1107 | delete: [201; 201), | ||
1108 | insert: "the_field", | ||
1109 | kind: Field, | ||
1110 | detail: "u32", | ||
1111 | score: TypeMatch, | ||
1112 | }, | ||
1113 | ] | ||
1114 | "### | ||
1115 | ); | ||
1116 | } | ||
1117 | |||
1118 | #[test] | ||
1119 | fn test_struct_field_completion_in_func_call_with_type_and_name() { | ||
1120 | assert_debug_snapshot!( | ||
1121 | do_reference_completion( | ||
1122 | r" | ||
1123 | struct A { another_field: i64, another_good_type: u32, the_field: u32 } | ||
1124 | fn test(the_field: u32) -> u32 { the_field } | ||
1125 | fn foo(a: A) { | ||
1126 | test(a.<|>) | ||
1127 | } | ||
1128 | ", | ||
1129 | ), | ||
1130 | @r###" | ||
1131 | [ | ||
1132 | CompletionItem { | ||
1133 | label: "another_field", | ||
1134 | source_range: [208; 208), | ||
1135 | delete: [208; 208), | ||
1136 | insert: "another_field", | ||
1137 | kind: Field, | ||
1138 | detail: "i64", | ||
1139 | }, | ||
1140 | CompletionItem { | ||
1141 | label: "another_good_type", | ||
1142 | source_range: [208; 208), | ||
1143 | delete: [208; 208), | ||
1144 | insert: "another_good_type", | ||
1145 | kind: Field, | ||
1146 | detail: "u32", | ||
1147 | score: TypeMatch, | ||
1148 | }, | ||
1149 | CompletionItem { | ||
1150 | label: "the_field", | ||
1151 | source_range: [208; 208), | ||
1152 | delete: [208; 208), | ||
1153 | insert: "the_field", | ||
1154 | kind: Field, | ||
1155 | detail: "u32", | ||
1156 | score: TypeAndNameMatch, | ||
1157 | }, | ||
1158 | ] | ||
1159 | "### | ||
1160 | ); | ||
1161 | } | ||
1162 | |||
1163 | #[test] | ||
1164 | fn test_struct_field_completion_in_record_lit() { | ||
1165 | assert_debug_snapshot!( | ||
1166 | do_reference_completion( | ||
1167 | r" | ||
1168 | struct A { another_field: i64, another_good_type: u32, the_field: u32 } | ||
1169 | struct B { my_string: String, my_vec: Vec<u32>, the_field: u32 } | ||
1170 | fn foo(a: A) { | ||
1171 | let b = B { | ||
1172 | the_field: a.<|> | ||
1173 | }; | ||
1174 | } | ||
1175 | ", | ||
1176 | ), | ||
1177 | @r###" | ||
1178 | [ | ||
1179 | CompletionItem { | ||
1180 | label: "another_field", | ||
1181 | source_range: [270; 270), | ||
1182 | delete: [270; 270), | ||
1183 | insert: "another_field", | ||
1184 | kind: Field, | ||
1185 | detail: "i64", | ||
1186 | }, | ||
1187 | CompletionItem { | ||
1188 | label: "another_good_type", | ||
1189 | source_range: [270; 270), | ||
1190 | delete: [270; 270), | ||
1191 | insert: "another_good_type", | ||
1192 | kind: Field, | ||
1193 | detail: "u32", | ||
1194 | score: TypeMatch, | ||
1195 | }, | ||
1196 | CompletionItem { | ||
1197 | label: "the_field", | ||
1198 | source_range: [270; 270), | ||
1199 | delete: [270; 270), | ||
1200 | insert: "the_field", | ||
1201 | kind: Field, | ||
1202 | detail: "u32", | ||
1203 | score: TypeAndNameMatch, | ||
1204 | }, | ||
1205 | ] | ||
1206 | "### | ||
1207 | ); | ||
1208 | } | ||
1209 | |||
1210 | #[test] | ||
1211 | fn test_struct_field_completion_in_record_lit_and_fn_call() { | ||
1212 | assert_debug_snapshot!( | ||
1213 | do_reference_completion( | ||
1214 | r" | ||
1215 | struct A { another_field: i64, another_good_type: u32, the_field: u32 } | ||
1216 | struct B { my_string: String, my_vec: Vec<u32>, the_field: u32 } | ||
1217 | fn test(the_field: i64) -> i64 { the_field } | ||
1218 | fn foo(a: A) { | ||
1219 | let b = B { | ||
1220 | the_field: test(a.<|>) | ||
1221 | }; | ||
1222 | } | ||
1223 | ", | ||
1224 | ), | ||
1225 | @r###" | ||
1226 | [ | ||
1227 | CompletionItem { | ||
1228 | label: "another_field", | ||
1229 | source_range: [336; 336), | ||
1230 | delete: [336; 336), | ||
1231 | insert: "another_field", | ||
1232 | kind: Field, | ||
1233 | detail: "i64", | ||
1234 | score: TypeMatch, | ||
1235 | }, | ||
1236 | CompletionItem { | ||
1237 | label: "another_good_type", | ||
1238 | source_range: [336; 336), | ||
1239 | delete: [336; 336), | ||
1240 | insert: "another_good_type", | ||
1241 | kind: Field, | ||
1242 | detail: "u32", | ||
1243 | }, | ||
1244 | CompletionItem { | ||
1245 | label: "the_field", | ||
1246 | source_range: [336; 336), | ||
1247 | delete: [336; 336), | ||
1248 | insert: "the_field", | ||
1249 | kind: Field, | ||
1250 | detail: "u32", | ||
1251 | }, | ||
1252 | ] | ||
1253 | "### | ||
1254 | ); | ||
1255 | } | ||
1256 | |||
1257 | #[test] | ||
1258 | fn test_struct_field_completion_in_fn_call_and_record_lit() { | ||
1259 | assert_debug_snapshot!( | ||
1260 | do_reference_completion( | ||
1261 | r" | ||
1262 | struct A { another_field: i64, another_good_type: u32, the_field: u32 } | ||
1263 | struct B { my_string: String, my_vec: Vec<u32>, the_field: u32 } | ||
1264 | fn test(the_field: i64) -> i64 { the_field } | ||
1265 | fn foo(a: A) { | ||
1266 | test(B { | ||
1267 | the_field: a.<|> | ||
1268 | }); | ||
1269 | } | ||
1270 | ", | ||
1271 | ), | ||
1272 | @r###" | ||
1273 | [ | ||
1274 | CompletionItem { | ||
1275 | label: "another_field", | ||
1276 | source_range: [328; 328), | ||
1277 | delete: [328; 328), | ||
1278 | insert: "another_field", | ||
1279 | kind: Field, | ||
1280 | detail: "i64", | ||
1281 | }, | ||
1282 | CompletionItem { | ||
1283 | label: "another_good_type", | ||
1284 | source_range: [328; 328), | ||
1285 | delete: [328; 328), | ||
1286 | insert: "another_good_type", | ||
1287 | kind: Field, | ||
1288 | detail: "u32", | ||
1289 | score: TypeMatch, | ||
1290 | }, | ||
1291 | CompletionItem { | ||
1292 | label: "the_field", | ||
1293 | source_range: [328; 328), | ||
1294 | delete: [328; 328), | ||
1295 | insert: "the_field", | ||
1296 | kind: Field, | ||
1297 | detail: "u32", | ||
1298 | score: TypeAndNameMatch, | ||
1299 | }, | ||
1300 | ] | ||
1301 | "### | ||
1302 | ); | ||
1303 | } | ||
1073 | } | 1304 | } |