@@ -170,4 +170,182 @@ final class StringLiteralTests: XCTestCase {
170
170
"""#
171
171
)
172
172
}
173
+
174
+ func testStringLiteralInExpr( ) {
175
+ let buildable = ExprSyntax (
176
+ #"""
177
+ "Validation failures: \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"
178
+ """#
179
+ )
180
+
181
+ AssertBuildResult (
182
+ buildable,
183
+ #"""
184
+ "Validation failures: \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"
185
+ """#
186
+ )
187
+ }
188
+
189
+ func testStringSegmentWithCode( ) {
190
+ let buildable = StringSegmentSyntax ( content: . stringSegment( #"\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"# ) )
191
+
192
+ AssertBuildResult (
193
+ buildable,
194
+ #"\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"#
195
+ )
196
+ }
197
+
198
+ func testStringLiteralSegmentWithCode( ) {
199
+ let buildable = StringLiteralSegmentsSyntax {
200
+ StringSegmentSyntax ( content: . stringSegment( #"Error validating child at index \(index) of \(nodeKind):"# ) , trailingTrivia: . newline)
201
+ StringSegmentSyntax ( content: . stringSegment( #"Node did not satisfy any node choice requirement."# ) , trailingTrivia: . newline)
202
+ StringSegmentSyntax ( content: . stringSegment( #"Validation failures:"# ) , trailingTrivia: . newline)
203
+ StringSegmentSyntax ( content: . stringSegment( #"\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"# ) )
204
+ }
205
+
206
+ AssertBuildResult (
207
+ buildable,
208
+ #"""
209
+ Error validating child at index \(index) of \(nodeKind):
210
+ Node did not satisfy any node choice requirement.
211
+ Validation failures:
212
+ \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
213
+ """#
214
+ )
215
+ }
216
+
217
+ func testMultiLineStringWithResultBuilder( ) {
218
+ let buildable = StringLiteralExprSyntax (
219
+ openQuote: . multilineStringQuoteToken( trailingTrivia: . newline) ,
220
+ segments: StringLiteralSegmentsSyntax {
221
+ StringSegmentSyntax ( content: . stringSegment( #"Error validating child at index \(index) of \(nodeKind):"# ) , trailingTrivia: . newline)
222
+ StringSegmentSyntax ( content: . stringSegment( #"Node did not satisfy any node choice requirement."# ) , trailingTrivia: . newline)
223
+ StringSegmentSyntax ( content: . stringSegment( #"Validation failures:"# ) , trailingTrivia: . newline)
224
+ StringSegmentSyntax ( content: . stringSegment( #"\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"# ) )
225
+ } ,
226
+ closeQuote: . multilineStringQuoteToken( leadingTrivia: . newline)
227
+ )
228
+
229
+ AssertBuildResult (
230
+ buildable,
231
+ #"""
232
+ """
233
+ Error validating child at index \(index) of \(nodeKind):
234
+ Node did not satisfy any node choice requirement.
235
+ Validation failures:
236
+ \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
237
+ """
238
+ """#
239
+ )
240
+ }
241
+
242
+ func testMultiLineStringWithFunctions( ) {
243
+ let buildable = StringLiteralExprSyntax (
244
+ openQuote: . multilineStringQuoteToken( trailingTrivia: . newline) ,
245
+ content:
246
+ #"""
247
+ assertionFailure("""
248
+ Error validating child at index \(index) of \(nodeKind):
249
+ Node did not satisfy any node choice requirement.
250
+ Validation failures:
251
+ \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n") )
252
+ """, file: file, line: line)
253
+ """#
254
+ ,
255
+ closeQuote: . multilineStringQuoteToken( leadingTrivia: . newline)
256
+ )
257
+
258
+ AssertBuildResult (
259
+ buildable,
260
+ ##"""
261
+ #"""
262
+ assertionFailure("""\#n Error validating child at index \(index) of \(nodeKind):\#n Node did not satisfy any node choice requirement.\#n Validation failures:\#n \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n") )\#n """, file: file, line: line)
263
+ """#
264
+ """##
265
+
266
+ )
267
+ }
268
+
269
+ func testMultiStringLiteralInExpr( ) {
270
+ let buildable = ExprSyntax (
271
+ #"""
272
+ assertionFailure("""
273
+ Error validating child at index \(index) of \(nodeKind):
274
+ Node did not satisfy any node choice requirement.
275
+ Validation failures:
276
+ \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
277
+ """, file: file, line: line)
278
+ """#
279
+ )
280
+
281
+ AssertBuildResult (
282
+ buildable,
283
+ #"""
284
+ assertionFailure("""
285
+ Error validating child at index \(index) of \(nodeKind):
286
+ Node did not satisfy any node choice requirement.
287
+ Validation failures:
288
+ \(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
289
+ """, file: file, line: line)
290
+ """#
291
+ )
292
+ }
293
+
294
+ func testMultiStringLiteralInIfExpr( ) {
295
+ let buildable = ExprSyntax (
296
+ #"""
297
+ if true {
298
+ assertionFailure("""
299
+ Error validating child at index
300
+ Node did not satisfy any node choice requirement.
301
+ Validation failures:
302
+ """)
303
+ }
304
+ """#
305
+ )
306
+
307
+ AssertBuildResult (
308
+ buildable,
309
+ #"""
310
+ if true {
311
+ assertionFailure("""
312
+ Error validating child at index
313
+ Node did not satisfy any node choice requirement.
314
+ Validation failures:
315
+ """)
316
+ }
317
+ """#
318
+ )
319
+ }
320
+
321
+ func testMultiStringLiteralOnNewlineInIfExpr( ) {
322
+ let buildable = ExprSyntax (
323
+ #"""
324
+ if true {
325
+ assertionFailure(
326
+ """
327
+ Error validating child at index
328
+ Node did not satisfy any node choice requirement.
329
+ Validation failures:
330
+ """
331
+ )
332
+ }
333
+ """#
334
+ )
335
+
336
+ AssertBuildResult (
337
+ buildable,
338
+ #"""
339
+ if true {
340
+ assertionFailure(
341
+ """
342
+ Error validating child at index
343
+ Node did not satisfy any node choice requirement.
344
+ Validation failures:
345
+ """
346
+ )
347
+ }
348
+ """#
349
+ )
350
+ }
173
351
}
0 commit comments