@@ -968,4 +968,102 @@ final class CasePathableMacroTests: XCTestCase {
968968 """#
969969 }
970970 }
971+
972+ func testComments( ) {
973+ assertMacro {
974+ """
975+ @CasePathable enum Foo {
976+ // Comment above case
977+ case bar
978+ /*Comment before case*/ case baz(Int)
979+ case fizz(buzz: String) // Comment on case
980+ case fizzier/*Comment in case*/(Int, buzzier: String)
981+ }
982+ """
983+ } expansion: {
984+ #"""
985+ enum Foo {
986+ // Comment above case
987+ case bar
988+ /*Comment before case*/ case baz(Int)
989+ case fizz(buzz: String) // Comment on case
990+ case fizzier/*Comment in case*/(Int, buzzier: String)
991+
992+ public struct AllCasePaths: Sequence {
993+ public subscript(root: Foo) -> PartialCaseKeyPath<Foo> {
994+ switch root {
995+ case .bar:
996+ return \.bar
997+ case .baz:
998+ return \.baz
999+ case .fizz:
1000+ return \.fizz
1001+ case .fizzier/*Comment in case*/:
1002+ return \.fizzier
1003+ }
1004+ }
1005+ // Comment above case
1006+ public var bar: CasePaths.AnyCasePath<Foo, Void> {
1007+ CasePaths.AnyCasePath<Foo, Void>(
1008+ embed: {
1009+ Foo.bar
1010+ },
1011+ extract: {
1012+ guard case .bar = $0 else {
1013+ return nil
1014+ }
1015+ return ()
1016+ }
1017+ )
1018+ }
1019+ /*Comment before case*/public var baz: CasePaths.AnyCasePath<Foo, Int> {
1020+ CasePaths.AnyCasePath<Foo, Int>(
1021+ embed: Foo.baz,
1022+ extract: {
1023+ guard case let .baz(v0) = $0 else {
1024+ return nil
1025+ }
1026+ return v0
1027+ }
1028+ )
1029+ }
1030+ public var fizz: CasePaths.AnyCasePath<Foo, String> {
1031+ CasePaths.AnyCasePath<Foo, String>(
1032+ embed: Foo.fizz,
1033+ extract: {
1034+ guard case let .fizz(v0) = $0 else {
1035+ return nil
1036+ }
1037+ return v0
1038+ }
1039+ )
1040+ }
1041+ public var fizzier: CasePaths.AnyCasePath<Foo, (Int, buzzier: String)> {
1042+ CasePaths.AnyCasePath<Foo, (Int, buzzier: String)>(
1043+ embed: Foo.fizzier,
1044+ extract: {
1045+ guard case let .fizzier(v0, v1) = $0 else {
1046+ return nil
1047+ }
1048+ return (v0, v1)
1049+ }
1050+ )
1051+ }
1052+ public func makeIterator() -> IndexingIterator<[PartialCaseKeyPath<Foo>]> {
1053+ var allCasePaths: [PartialCaseKeyPath<Foo>] = []
1054+ allCasePaths.append(\.bar)
1055+ allCasePaths.append(\.baz)
1056+ allCasePaths.append(\.fizz)
1057+ allCasePaths.append(\.fizzier/*Comment in case*/)
1058+ return allCasePaths.makeIterator()
1059+ }
1060+ }
1061+ public static var allCasePaths: AllCasePaths { AllCasePaths() }
1062+ }
1063+
1064+ extension Foo: CasePaths.CasePathable {
1065+ }
1066+ """#
1067+ }
1068+ }
9711069}
0 commit comments