@@ -113,14 +113,85 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
113
113
1 │ let pi = 3.14159
114
114
2 │ #myAssert(pi == 3)
115
115
∣ ╰─ in expansion of macro 'myAssert' here
116
- ╭-── #myAssert───────────────────────────────────────────────────────────────
116
+ ╭-── #myAssert───────────────────────────────────────────────────────
117
117
|1 │ let __a = pi
118
118
|2 │ let __b = 3
119
119
|3 │ if !(__a == __b) {
120
120
| ∣ ╰─ no matching operator '==' for types 'Double' and 'Int'
121
121
|4 │ fatalError( " assertion failed: pi != 3 " )
122
122
|5 │ }
123
- ╰-───────────────────────────────────────────────────────────────────────────
123
+ ╰-───────────────────────────────────────────────────────────────────
124
+ 3 │ print( " hello "
125
+ ∣ ╰─ expected ')' to end function call
126
+
127
+ """
128
+ )
129
+ }
130
+
131
+ func testGroupingForDoubleNestedMacroExpansion( ) {
132
+ var group = GroupedDiagnostics ( )
133
+
134
+ // Main source file.
135
+ let ( mainSourceID, mainSourceMarkers) = group. addTestFile (
136
+ """
137
+ let pi = 3.14159
138
+ 0️⃣#myAssert(pi == 3)
139
+ print( " hello "
140
+ """ ,
141
+ displayName: " main.swift " ,
142
+ extraDiagnostics: [ " 0️⃣ " : ( " in expansion of macro 'myAssert' here " , . note) ]
143
+ )
144
+ let inExpansionNotePos = mainSourceMarkers [ " 0️⃣ " ] !
145
+
146
+ // Outer expansion source file
147
+ let ( outerExpansionSourceID, outerExpansionSourceMarkers) = group. addTestFile (
148
+ """
149
+ let __a = pi
150
+ let __b = 3
151
+ if 0️⃣#invertedEqualityCheck(__a, __b) {
152
+ fatalError( " assertion failed: pi != 3 " )
153
+ }
154
+ """ ,
155
+ displayName: " #myAssert " ,
156
+ parent: ( mainSourceID, inExpansionNotePos) ,
157
+ extraDiagnostics: [
158
+ " 0️⃣ " : ( " in expansion of macro 'invertedEqualityCheck' here " , . note)
159
+ ]
160
+ )
161
+ let inInnerExpansionNotePos = outerExpansionSourceMarkers [ " 0️⃣ " ] !
162
+
163
+ // Expansion source file
164
+ _ = group. addTestFile (
165
+ """
166
+ !(__a 0️⃣== __b)
167
+ """ ,
168
+ displayName: " #invertedEqualityCheck " ,
169
+ parent: ( outerExpansionSourceID, inInnerExpansionNotePos) ,
170
+ extraDiagnostics: [
171
+ " 0️⃣ " : ( " no matching operator '==' for types 'Double' and 'Int' " , . error)
172
+ ]
173
+ )
174
+
175
+ let formatter = DiagnosticsFormatter ( )
176
+ let annotated = formatter. annotateSources ( in: group)
177
+ print ( annotated)
178
+ AssertStringsEqualWithDiff ( annotated, """
179
+ === main.swift ===
180
+ 1 │ let pi = 3.14159
181
+ 2 │ #myAssert(pi == 3)
182
+ ∣ ╰─ in expansion of macro 'myAssert' here
183
+ ╭-── #myAssert───────────────────────────────────────────────────────
184
+ |1 │ let __a = pi
185
+ |2 │ let __b = 3
186
+ |3 │ if #invertedEqualityCheck(__a, __b) {
187
+ | ∣ ╰─ in expansion of macro 'invertedEqualityCheck' here
188
+ | ╭-── #invertedEqualityCheck──────────────────────────────────────
189
+ | |1 │ !(__a == __b)
190
+ | | ∣ ╰─ no matching operator '==' for types 'Double' and 'Int'
191
+ | ╰-───────────────────────────────────────────────────────────────
192
+ |4 │ fatalError( " assertion failed: pi != 3 " )
193
+ |5 │ }
194
+ ╰-───────────────────────────────────────────────────────────────────
124
195
3 │ print( " hello "
125
196
∣ ╰─ expected ')' to end function call
126
197
0 commit comments