@@ -79,6 +79,32 @@ final class AddAsyncMacroTests: XCTestCase {
79
79
)
80
80
}
81
81
82
+ func testImplicitVoidResult( ) {
83
+ assertMacroExpansion (
84
+ """
85
+ @AddAsync
86
+ func d(a: Int, completionBlock: @escaping (Bool) -> Void) {
87
+ }
88
+ """ ,
89
+ expandedSource: """
90
+ func d(a: Int, completionBlock: @escaping (Bool) -> Void) {
91
+ }
92
+
93
+ func d(a: Int) async -> Bool {
94
+ await withCheckedContinuation { continuation in
95
+ d(a: a) { returnValue in
96
+
97
+ continuation.resume(returning: returnValue)
98
+ }
99
+ }
100
+
101
+ }
102
+ """ ,
103
+ macros: macros,
104
+ indentationWidth: . spaces( 2 )
105
+ )
106
+ }
107
+
82
108
func testExpansionOnStoredPropertyEmitsError( ) {
83
109
assertMacroExpansion (
84
110
"""
@@ -105,18 +131,18 @@ final class AddAsyncMacroTests: XCTestCase {
105
131
)
106
132
}
107
133
108
- func testExpansionOnAsyncFunctionEmitsError ( ) {
134
+ func testNonVoidResult ( ) {
109
135
assertMacroExpansion (
110
136
"""
111
137
struct Test {
112
138
@AddAsync
113
- async func sayHello() {
139
+ func sayHello() -> Int {
114
140
}
115
141
}
116
142
""" ,
117
143
expandedSource: """
118
144
struct Test {
119
- async func sayHello() {
145
+ func sayHello() -> Int {
120
146
}
121
147
}
122
148
""" ,
@@ -132,4 +158,50 @@ final class AddAsyncMacroTests: XCTestCase {
132
158
indentationWidth: . spaces( 2 )
133
159
)
134
160
}
161
+
162
+ func testAlreadyAsync( ) {
163
+ assertMacroExpansion (
164
+ """
165
+ @AddAsync
166
+ func d(a: Int, completionBlock: @escaping (Bool) -> Void) async {
167
+ }
168
+ """ ,
169
+ expandedSource: """
170
+ func d(a: Int, completionBlock: @escaping (Bool) -> Void) async {
171
+ }
172
+ """ ,
173
+ diagnostics: [
174
+ DiagnosticSpec (
175
+ message: " @addAsync requires an non async function " ,
176
+ line: 1 ,
177
+ column: 1 ,
178
+ severity: . error
179
+ )
180
+ ] ,
181
+ macros: macros,
182
+ indentationWidth: . spaces( 2 )
183
+ )
184
+ }
185
+
186
+ func testNoCompletionHandler( ) {
187
+ assertMacroExpansion (
188
+ """
189
+ @AddAsync
190
+ func sayHello(x: Int) {}
191
+ """ ,
192
+ expandedSource: """
193
+ func sayHello(x: Int) {}
194
+ """ ,
195
+ diagnostics: [
196
+ DiagnosticSpec (
197
+ message: " @addAsync requires an function that has a completion handler as last parameter " ,
198
+ line: 1 ,
199
+ column: 1 ,
200
+ severity: . error
201
+ )
202
+ ] ,
203
+ macros: macros,
204
+ indentationWidth: . spaces( 2 )
205
+ )
206
+ }
135
207
}
0 commit comments