|
1294 | 1294 | """#
|
1295 | 1295 | }
|
1296 | 1296 | }
|
| 1297 | + |
| 1298 | + func testTrailingCommas() { |
| 1299 | + assertMacro { |
| 1300 | + """ |
| 1301 | + @CasePathable enum Action { |
| 1302 | + case exampleAction( |
| 1303 | + param1: String, |
| 1304 | + param2: String, |
| 1305 | + param3: String, |
| 1306 | + ) |
| 1307 | + case singleParam( |
| 1308 | + value: Int, |
| 1309 | + ) |
| 1310 | + case multipleWithLabels( |
| 1311 | + first: String, |
| 1312 | + second: Bool, |
| 1313 | + third: Double, |
| 1314 | + ) |
| 1315 | + } |
| 1316 | + """ |
| 1317 | + } expansion: { |
| 1318 | + #""" |
| 1319 | + enum Action { |
| 1320 | + case exampleAction( |
| 1321 | + param1: String, |
| 1322 | + param2: String, |
| 1323 | + param3: String, |
| 1324 | + ) |
| 1325 | + case singleParam( |
| 1326 | + value: Int, |
| 1327 | + ) |
| 1328 | + case multipleWithLabels( |
| 1329 | + first: String, |
| 1330 | + second: Bool, |
| 1331 | + third: Double, |
| 1332 | + ) |
| 1333 | + |
| 1334 | + public struct AllCasePaths: CasePaths.CasePathReflectable, Swift.Sendable, Swift.Sequence { |
| 1335 | + public subscript(root: Action) -> CasePaths.PartialCaseKeyPath<Action> { |
| 1336 | + if root.is(\.exampleAction) { |
| 1337 | + return \.exampleAction |
| 1338 | + } |
| 1339 | + if root.is(\.singleParam) { |
| 1340 | + return \.singleParam |
| 1341 | + } |
| 1342 | + if root.is(\.multipleWithLabels) { |
| 1343 | + return \.multipleWithLabels |
| 1344 | + } |
| 1345 | + return \.never |
| 1346 | + } |
| 1347 | + public var exampleAction: CasePaths.AnyCasePath<Action, (param1: String, |
| 1348 | + param2: String, |
| 1349 | + param3: String)> { |
| 1350 | + ._$embed(Action.exampleAction) { |
| 1351 | + guard case let .exampleAction(v0, v1, v2) = $0 else { |
| 1352 | + return nil |
| 1353 | + } |
| 1354 | + return (v0, v1, v2) |
| 1355 | + } |
| 1356 | + } |
| 1357 | + public var singleParam: CasePaths.AnyCasePath<Action, Int> { |
| 1358 | + ._$embed(Action.singleParam) { |
| 1359 | + guard case let .singleParam(v0) = $0 else { |
| 1360 | + return nil |
| 1361 | + } |
| 1362 | + return v0 |
| 1363 | + } |
| 1364 | + } |
| 1365 | + public var multipleWithLabels: CasePaths.AnyCasePath<Action, (first: String, |
| 1366 | + second: Bool, |
| 1367 | + third: Double)> { |
| 1368 | + ._$embed(Action.multipleWithLabels) { |
| 1369 | + guard case let .multipleWithLabels(v0, v1, v2) = $0 else { |
| 1370 | + return nil |
| 1371 | + } |
| 1372 | + return (v0, v1, v2) |
| 1373 | + } |
| 1374 | + } |
| 1375 | + public func makeIterator() -> Swift.IndexingIterator<[CasePaths.PartialCaseKeyPath<Action>]> { |
| 1376 | + var allCasePaths: [CasePaths.PartialCaseKeyPath<Action>] = [] |
| 1377 | + allCasePaths.append(\.exampleAction) |
| 1378 | + allCasePaths.append(\.singleParam) |
| 1379 | + allCasePaths.append(\.multipleWithLabels) |
| 1380 | + return allCasePaths.makeIterator() |
| 1381 | + } |
| 1382 | + } |
| 1383 | + public static var allCasePaths: AllCasePaths { AllCasePaths() } |
| 1384 | + } |
| 1385 | + |
| 1386 | + extension Action: CasePaths.CasePathable, CasePaths.CasePathIterable { |
| 1387 | + } |
| 1388 | + """# |
| 1389 | + } |
| 1390 | + } |
| 1391 | + |
1297 | 1392 | }
|
1298 | 1393 | #endif
|
0 commit comments