@@ -1170,14 +1170,15 @@ final class RenameTests: XCTestCase {
1170
1170
}
1171
1171
1172
1172
func testRenameEnumCaseWithUnlabeledAssociatedValue( ) async throws {
1173
+ try await SkipUnless . sourcekitdCanRenameEnumCaseLabels ( )
1173
1174
try await assertSingleFileRename (
1174
1175
"""
1175
1176
enum MyEnum {
1176
1177
case 1️⃣myCase(String)
1177
1178
}
1178
1179
""" ,
1179
1180
newName: " newName " ,
1180
- expectedPrepareRenamePlaceholder: " myCase " ,
1181
+ expectedPrepareRenamePlaceholder: " myCase(_:) " ,
1181
1182
expected: """
1182
1183
enum MyEnum {
1183
1184
case newName(String)
@@ -1187,39 +1188,127 @@ final class RenameTests: XCTestCase {
1187
1188
}
1188
1189
1189
1190
func testAddLabelToEnumCase( ) async throws {
1190
- // We don't support renaming enum parameter labels at the moment
1191
- // (https://github.com/apple/sourcekit-lsp/issues/1228)
1191
+ try await SkipUnless . sourcekitdCanRenameEnumCaseLabels ( )
1192
1192
try await assertSingleFileRename (
1193
1193
"""
1194
1194
enum MyEnum {
1195
1195
case 1️⃣myCase(String)
1196
1196
}
1197
1197
""" ,
1198
1198
newName: " newName(newLabel:) " ,
1199
- expectedPrepareRenamePlaceholder: " myCase " ,
1199
+ expectedPrepareRenamePlaceholder: " myCase(_:) " ,
1200
1200
expected: """
1201
1201
enum MyEnum {
1202
- case newName(String)
1202
+ case newName(newLabel: String)
1203
1203
}
1204
1204
"""
1205
1205
)
1206
1206
}
1207
1207
1208
- func testRemoveLabelToEnumCase( ) async throws {
1209
- // We don't support renaming enum parameter labels at the moment
1210
- // (https://github.com/apple/sourcekit-lsp/issues/1228)
1208
+ func testRemoveLabelFromEnumCase( ) async throws {
1209
+ try await SkipUnless . sourcekitdCanRenameEnumCaseLabels ( )
1211
1210
try await assertSingleFileRename (
1212
1211
"""
1213
1212
enum MyEnum {
1214
- case 1️⃣myCase(label: String)
1213
+ case myCase(label: String)
1214
+ }
1215
+
1216
+ func test() {
1217
+ _ = MyEnum.2️⃣myCase(label: " abc " )
1215
1218
}
1216
1219
""" ,
1217
1220
newName: " newName(_:) " ,
1218
- expectedPrepareRenamePlaceholder: " myCase " ,
1221
+ expectedPrepareRenamePlaceholder: " myCase(label:) " ,
1222
+ expected: """
1223
+ enum MyEnum {
1224
+ case newName(_ label: String)
1225
+ }
1226
+
1227
+ func test() {
1228
+ _ = MyEnum.newName( " abc " )
1229
+ }
1230
+ """
1231
+ )
1232
+ }
1233
+
1234
+ func testRenameEnumCaseWithUnderscoreLabel( ) async throws {
1235
+ try await SkipUnless . sourcekitdCanRenameEnumCaseLabels ( )
1236
+ try await assertSingleFileRename (
1237
+ """
1238
+ enum MyEnum {
1239
+ case myCase(_ label: String)
1240
+ }
1241
+
1242
+ func test() {
1243
+ _ = MyEnum.2️⃣myCase( " abc " )
1244
+ }
1245
+ """ ,
1246
+ newName: " newName(_:) " ,
1247
+ expectedPrepareRenamePlaceholder: " myCase(_:) " ,
1248
+ expected: """
1249
+ enum MyEnum {
1250
+ case newName(_ label: String)
1251
+ }
1252
+
1253
+ func test() {
1254
+ _ = MyEnum.newName( " abc " )
1255
+ }
1256
+ """
1257
+ )
1258
+ }
1259
+
1260
+ func testRenameEnumCaseWithUnderscoreToLabelMatchingInternalName( ) async throws {
1261
+ try await SkipUnless . sourcekitdCanRenameEnumCaseLabels ( )
1262
+ try await assertSingleFileRename (
1263
+ """
1264
+ enum MyEnum {
1265
+ case myCase(_ label: String)
1266
+ }
1267
+
1268
+ func test() {
1269
+ _ = MyEnum.2️⃣myCase( " abc " )
1270
+ }
1271
+ """ ,
1272
+ newName: " newName(label:) " ,
1273
+ expectedPrepareRenamePlaceholder: " myCase(_:) " ,
1219
1274
expected: """
1220
1275
enum MyEnum {
1221
1276
case newName(label: String)
1222
1277
}
1278
+
1279
+ func test() {
1280
+ _ = MyEnum.newName(label: " abc " )
1281
+ }
1282
+ """
1283
+ )
1284
+ }
1285
+
1286
+ func testRenameEnumCaseWithUnderscoreToLabelNotMatchingInternalName( ) async throws {
1287
+ try await SkipUnless . sourcekitdCanRenameEnumCaseLabels ( )
1288
+ // Note that the renamed code doesn't compile because enum cases can't have an external and internal parameter name.
1289
+ // But it's probably the best thing we can do because we don't want to erase the user-specified internal name, which
1290
+ // they didn't request to rename. Also, this is a pretty niche case and having a special case for it is probably not
1291
+ // worth it.
1292
+ try await assertSingleFileRename (
1293
+ """
1294
+ enum MyEnum {
1295
+ case myCase(_ label: String)
1296
+ }
1297
+
1298
+ func test() {
1299
+ _ = MyEnum.2️⃣myCase( " abc " )
1300
+ }
1301
+ """ ,
1302
+ newName: " newName(publicLabel:) " ,
1303
+ expectedPrepareRenamePlaceholder: " myCase(_:) " ,
1304
+ expected: """
1305
+ enum MyEnum {
1306
+ case newName(publicLabel label: String)
1307
+ }
1308
+
1309
+ func test() {
1310
+ _ = MyEnum.newName(publicLabel: " abc " )
1311
+ }
1223
1312
"""
1224
1313
)
1225
1314
}
0 commit comments