File tree Expand file tree Collapse file tree 10 files changed +93
-99
lines changed
Tests/MacroExamples/Implementation Expand file tree Collapse file tree 10 files changed +93
-99
lines changed Original file line number Diff line number Diff line change @@ -81,16 +81,14 @@ public struct DictionaryStoragePropertyMacro: AccessorMacro {
81
81
82
82
return [
83
83
"""
84
-
85
- get {
86
- _storage[ \( literal: identifier. text) , default: \( defaultValue) ] as! \( type)
87
- }
84
+ get {
85
+ _storage[ \( literal: identifier. text) , default: \( defaultValue) ] as! \( type)
86
+ }
88
87
""" ,
89
88
"""
90
-
91
- set {
92
- _storage[ \( literal: identifier. text) ] = newValue
93
- }
89
+ set {
90
+ _storage[ \( literal: identifier. text) ] = newValue
91
+ }
94
92
""" ,
95
93
]
96
94
}
Original file line number Diff line number Diff line change @@ -44,11 +44,9 @@ public enum CustomCodable: MemberMacro {
44
44
} )
45
45
46
46
let codingKeys : DeclSyntax = """
47
-
48
- enum CodingKeys: String, CodingKey {
49
- \( raw: cases. joined ( separator: " \n " ) )
50
- }
51
-
47
+ enum CodingKeys: String, CodingKey {
48
+ \( raw: cases. joined ( separator: " \n " ) )
49
+ }
52
50
"""
53
51
54
52
return [ codingKeys]
Original file line number Diff line number Diff line change @@ -41,36 +41,39 @@ public struct MetaEnumMacro {
41
41
42
42
func makeMetaEnum( ) -> DeclSyntax {
43
43
// FIXME: Why does this need to be a string to make trailing trivia work properly?
44
- let caseDecls = childCases. map { childCase in
45
- " case \( childCase. name) "
46
- } . joined ( separator: " \n " )
44
+ let caseDecls =
45
+ childCases
46
+ . map { childCase in
47
+ " case \( childCase. name) "
48
+ }
49
+ . joined ( separator: " \n " )
47
50
48
51
return """
49
-
50
- \( access) enum Meta {
52
+ \( access) enum Meta {
51
53
\( raw: caseDecls)
52
54
\( makeMetaInit ( ) )
53
- }
54
-
55
+ }
55
56
"""
56
57
}
57
58
58
59
func makeMetaInit( ) -> DeclSyntax {
59
60
// FIXME: Why does this need to be a string to make trailing trivia work properly?
60
- let caseStatements = childCases. map { childCase in
61
- """
62
- case . \( childCase. name) :
63
- self = . \( childCase. name)
64
- """
65
- } . joined ( separator: " \n " )
61
+ let caseStatements =
62
+ childCases
63
+ . map { childCase in
64
+ """
65
+ case . \( childCase. name) :
66
+ self = . \( childCase. name)
67
+ """
68
+ }
69
+ . joined ( separator: " \n " )
66
70
67
71
return """
68
-
69
- \( access) init(_ \( parentParamName) : \( parentTypeName) ) {
70
- switch \( parentParamName) {
72
+ \( access) init(_ \( parentParamName) : \( parentTypeName) ) {
73
+ switch \( parentParamName) {
71
74
\( raw: caseStatements)
72
- }
73
- }
75
+ }
76
+ }
74
77
"""
75
78
}
76
79
}
Original file line number Diff line number Diff line change @@ -101,12 +101,12 @@ public struct AddAsyncMacro: PeerMacro {
101
101
102
102
let switchBody : ExprSyntax =
103
103
"""
104
- switch returnValue {
105
- case .success(let value):
106
- continuation.resume(returning: value)
107
- case .failure(let error):
108
- continuation.resume(throwing: error)
109
- }
104
+ switch returnValue {
105
+ case .success(let value):
106
+ continuation.resume(returning: value)
107
+ case .failure(let error):
108
+ continuation.resume(throwing: error)
109
+ }
110
110
"""
111
111
112
112
let newBody : ExprSyntax =
@@ -115,8 +115,7 @@ public struct AddAsyncMacro: PeerMacro {
115
115
\( raw: isResultReturn ? " try await withCheckedThrowingContinuation { continuation in " : " await withCheckedContinuation { continuation in " )
116
116
\( raw: funcDecl. name) ( \( raw: callArguments. joined ( separator: " , " ) ) ) { \( raw: returnType != nil ? " returnValue in " : " " )
117
117
118
- \( raw: isResultReturn ? switchBody : " continuation.resume(returning: \( raw: returnType != nil ? " returnValue " : " () " ) ) " )
119
-
118
+ \( raw: isResultReturn ? switchBody : " continuation.resume(returning: \( raw: returnType != nil ? " returnValue " : " () " ) ) " )
120
119
}
121
120
}
122
121
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ func runExpressionMacrosPlayground() {
45
45
// malformed an error is emitted. Otherwise a non-optional URL is expanded.
46
46
print ( #URL( " https://swift.org/ " ) )
47
47
48
- let domain = " domain.com "
48
+ // let domain = "domain.com"
49
49
//print(#URL("https://\(domain)/api/path")) // error: #URL requires a static string literal
50
50
//print(#URL("https://not a url.com")) // error: Malformed url
51
51
Original file line number Diff line number Diff line change @@ -34,19 +34,19 @@ final class DictionaryStorageMacroTests: XCTestCase {
34
34
struct Point {
35
35
var x: Int = 1 {
36
36
get {
37
- _storage[ " x " , default: 1] as! Int
38
- }
37
+ _storage[ " x " , default: 1] as! Int
38
+ }
39
39
set {
40
- _storage[ " x " ] = newValue
41
- }
40
+ _storage[ " x " ] = newValue
41
+ }
42
42
}
43
43
var y: Int = 2 {
44
44
get {
45
- _storage[ " y " , default: 2] as! Int
46
- }
45
+ _storage[ " y " , default: 2] as! Int
46
+ }
47
47
set {
48
- _storage[ " y " ] = newValue
49
- }
48
+ _storage[ " y " ] = newValue
49
+ }
50
50
}
51
51
52
52
var _storage: [String: Any] = [:]
Original file line number Diff line number Diff line change @@ -59,16 +59,16 @@ final class OptionSetMacroTests: XCTestCase {
59
59
}
60
60
61
61
static let nextDay: Self =
62
- Self (rawValue: 1 << Options.nextDay.rawValue)
62
+ Self(rawValue: 1 << Options.nextDay.rawValue)
63
63
64
64
static let secondDay: Self =
65
- Self (rawValue: 1 << Options.secondDay.rawValue)
65
+ Self(rawValue: 1 << Options.secondDay.rawValue)
66
66
67
67
static let priority: Self =
68
- Self (rawValue: 1 << Options.priority.rawValue)
68
+ Self(rawValue: 1 << Options.priority.rawValue)
69
69
70
70
static let standard: Self =
71
- Self (rawValue: 1 << Options.standard.rawValue)
71
+ Self(rawValue: 1 << Options.standard.rawValue)
72
72
}
73
73
74
74
extension ShippingOptions: OptionSet {
@@ -110,10 +110,10 @@ final class OptionSetMacroTests: XCTestCase {
110
110
}
111
111
112
112
public static let nextDay: Self =
113
- Self (rawValue: 1 << Options.nextDay.rawValue)
113
+ Self(rawValue: 1 << Options.nextDay.rawValue)
114
114
115
115
public static let standard: Self =
116
- Self (rawValue: 1 << Options.standard.rawValue)
116
+ Self(rawValue: 1 << Options.standard.rawValue)
117
117
}
118
118
""" ,
119
119
macros: macros,
Original file line number Diff line number Diff line change @@ -33,9 +33,9 @@ final class CustomCodableTests: XCTestCase {
33
33
let age: Int
34
34
35
35
enum CodingKeys: String, CodingKey {
36
- case name
37
- case age
38
- }
36
+ case name
37
+ case age
38
+ }
39
39
}
40
40
""" ,
41
41
macros: macros,
@@ -62,9 +62,9 @@ final class CustomCodableTests: XCTestCase {
62
62
func randomFunction() {}
63
63
64
64
enum CodingKeys: String, CodingKey {
65
- case name
66
- case age = " user_age "
67
- }
65
+ case name
66
+ case age = " user_age "
67
+ }
68
68
}
69
69
""" ,
70
70
macros: macros,
Original file line number Diff line number Diff line change @@ -36,24 +36,23 @@ final class MetaEnumMacroTests: XCTestCase {
36
36
case null
37
37
38
38
enum Meta {
39
- case integer
40
- case text
41
- case boolean
42
- case null
43
-
44
- init(_ __macro_local_6parentfMu_: Cell) {
45
- switch __macro_local_6parentfMu_ {
46
- case .integer:
47
- self = .integer
48
- case .text:
49
- self = .text
50
- case .boolean:
51
- self = .boolean
52
- case .null:
53
- self = .null
54
- }
55
- }
39
+ case integer
40
+ case text
41
+ case boolean
42
+ case null
43
+ init(_ __macro_local_6parentfMu_: Cell) {
44
+ switch __macro_local_6parentfMu_ {
45
+ case .integer:
46
+ self = .integer
47
+ case .text:
48
+ self = .text
49
+ case .boolean:
50
+ self = .boolean
51
+ case .null:
52
+ self = .null
53
+ }
56
54
}
55
+ }
57
56
}
58
57
""" ,
59
58
macros: macros,
@@ -77,21 +76,20 @@ final class MetaEnumMacroTests: XCTestCase {
77
76
case boolean(Bool)
78
77
79
78
public enum Meta {
80
- case integer
81
- case text
82
- case boolean
83
-
84
- public init(_ __macro_local_6parentfMu_: Cell) {
85
- switch __macro_local_6parentfMu_ {
86
- case .integer:
87
- self = .integer
88
- case .text:
89
- self = .text
90
- case .boolean:
91
- self = .boolean
92
- }
93
- }
79
+ case integer
80
+ case text
81
+ case boolean
82
+ public init(_ __macro_local_6parentfMu_: Cell) {
83
+ switch __macro_local_6parentfMu_ {
84
+ case .integer:
85
+ self = .integer
86
+ case .text:
87
+ self = .text
88
+ case .boolean:
89
+ self = .boolean
90
+ }
94
91
}
92
+ }
95
93
}
96
94
""" ,
97
95
macros: macros,
Original file line number Diff line number Diff line change @@ -36,12 +36,11 @@ final class AddAsyncMacroTests: XCTestCase {
36
36
c(a: a, for: b, value) { returnValue in
37
37
38
38
switch returnValue {
39
- case .success(let value):
40
- continuation.resume(returning: value)
41
- case .failure(let error):
42
- continuation.resume(throwing: error)
43
- }
44
-
39
+ case .success(let value):
40
+ continuation.resume(returning: value)
41
+ case .failure(let error):
42
+ continuation.resume(throwing: error)
43
+ }
45
44
}
46
45
}
47
46
}
@@ -68,8 +67,7 @@ final class AddAsyncMacroTests: XCTestCase {
68
67
await withCheckedContinuation { continuation in
69
68
d(a: a, for: b, value) { returnValue in
70
69
71
- continuation.resume(returning: returnValue)
72
-
70
+ continuation.resume(returning: returnValue)
73
71
}
74
72
}
75
73
}
You can’t perform that action at this time.
0 commit comments