File tree Expand file tree Collapse file tree 3 files changed +69
-2
lines changed
Sources/MacroExamples/Implementation/Peer
Tests/MacroExamples/Implementation Expand file tree Collapse file tree 3 files changed +69
-2
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,9 @@ public struct AddCompletionHandlerMacro: PeerMacro {
34
34
var newEffects : FunctionEffectSpecifiersSyntax
35
35
if let existingEffects = funcDecl. signature. effectSpecifiers {
36
36
newEffects = existingEffects
37
- newEffects. asyncSpecifier = . keyword( . async)
37
+ newEffects. asyncSpecifier = . keyword( . async, trailingTrivia : . space )
38
38
} else {
39
- newEffects = FunctionEffectSpecifiersSyntax ( asyncSpecifier: . keyword( . async) )
39
+ newEffects = FunctionEffectSpecifiersSyntax ( asyncSpecifier: . keyword( . async, trailingTrivia : . space ) )
40
40
}
41
41
42
42
var newSignature = funcDecl. signature
Original file line number Diff line number Diff line change @@ -39,6 +39,33 @@ final class AddBlockerTests: XCTestCase {
39
39
)
40
40
}
41
41
42
+ func testExpansionWithSubtractionAppliesFixIt( ) {
43
+ assertMacroExpansion (
44
+ """
45
+ #addBlocker(x * y + z)
46
+ """ ,
47
+ expandedSource: """
48
+ x * y - z
49
+ """ ,
50
+ diagnostics: [
51
+ DiagnosticSpec (
52
+ message: " blocked an add; did you mean to subtract? " ,
53
+ line: 1 ,
54
+ column: 19 ,
55
+ severity: . warning,
56
+ fixIts: [ FixItSpec ( message: " use '-' " ) ]
57
+ )
58
+ ] ,
59
+ macros: macros,
60
+ applyFixIts: [ " use '-' " ] ,
61
+ fixedSource:
62
+ """
63
+ #addBlocker(x * y - z)
64
+ """ ,
65
+ indentationWidth: . spaces( 2 )
66
+ )
67
+ }
68
+
42
69
func testExpansionPreservesSubtraction( ) {
43
70
assertMacroExpansion (
44
71
"""
Original file line number Diff line number Diff line change @@ -98,4 +98,44 @@ final class AddCompletionHandlerMacroTests: XCTestCase {
98
98
indentationWidth: . spaces( 2 )
99
99
)
100
100
}
101
+
102
+ func testExpansionOnNonAsyncFunctionAppliesFixIt( ) {
103
+ assertMacroExpansion (
104
+ """
105
+ struct Test {
106
+ @AddCompletionHandler
107
+ func fetchData() -> String {
108
+ return " Hello, World! "
109
+ }
110
+ }
111
+ """ ,
112
+ expandedSource: """
113
+ struct Test {
114
+ func fetchData() -> String {
115
+ return " Hello, World! "
116
+ }
117
+ }
118
+ """ ,
119
+ diagnostics: [
120
+ DiagnosticSpec (
121
+ message: " can only add a completion-handler variant to an 'async' function " ,
122
+ line: 3 ,
123
+ column: 3 ,
124
+ severity: . error,
125
+ fixIts: [ FixItSpec ( message: " add 'async' " ) ]
126
+ )
127
+ ] ,
128
+ macros: macros,
129
+ applyFixIts: [ " add 'async' " ] ,
130
+ fixedSource: """
131
+ struct Test {
132
+ @AddCompletionHandler
133
+ func fetchData() async -> String {
134
+ return " Hello, World! "
135
+ }
136
+ }
137
+ """ ,
138
+ indentationWidth: . spaces( 2 )
139
+ )
140
+ }
101
141
}
You can’t perform that action at this time.
0 commit comments