Skip to content

Commit 8372760

Browse files
committed
Add tests cases for failing multi line string
1 parent 70eb87b commit 8372760

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed

Tests/SwiftSyntaxBuilderTest/StringLiteralTests.swift

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,186 @@ final class StringLiteralTests: XCTestCase {
170170
"""#
171171
)
172172
}
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+
ExpressionSegmentSyntax(
225+
expressions: TupleExprElementListSyntax {
226+
TupleExprElementSyntax(expression: ExprSyntax(#"nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"#))
227+
}
228+
)
229+
},
230+
closeQuote: .multilineStringQuoteToken(leadingTrivia: .newline)
231+
)
232+
233+
AssertBuildResult(
234+
buildable,
235+
#"""
236+
"""
237+
Error validating child at index \(index) of \(nodeKind):
238+
Node did not satisfy any node choice requirement.
239+
Validation failures:
240+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
241+
"""
242+
"""#
243+
)
244+
}
245+
246+
func testMultiLineStringWithFunctions() {
247+
let buildable = StringLiteralExprSyntax(
248+
openQuote: .multilineStringQuoteToken(trailingTrivia: .newline),
249+
content:
250+
#"""
251+
assertionFailure("""
252+
Error validating child at index \(index) of \(nodeKind):
253+
Node did not satisfy any node choice requirement.
254+
Validation failures:
255+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n") )
256+
""", file: file, line: line)
257+
"""#
258+
,
259+
closeQuote: .multilineStringQuoteToken(leadingTrivia: .newline)
260+
)
261+
262+
AssertBuildResult(
263+
buildable,
264+
##"""
265+
#"""
266+
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)
267+
"""#
268+
"""##
269+
270+
)
271+
}
272+
273+
func testMultiStringLiteralInExpr() {
274+
let buildable = ExprSyntax(
275+
#"""
276+
assertionFailure("""
277+
Error validating child at index \(index) of \(nodeKind):
278+
Node did not satisfy any node choice requirement.
279+
Validation failures:
280+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
281+
""", file: file, line: line)
282+
"""#
283+
)
284+
285+
AssertBuildResult(
286+
buildable,
287+
#"""
288+
assertionFailure("""
289+
Error validating child at index \(index) of \(nodeKind):
290+
Node did not satisfy any node choice requirement.
291+
Validation failures:
292+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
293+
""", file: file, line: line)
294+
"""#
295+
)
296+
}
297+
298+
func testMultiStringLiteralInIfExpr() {
299+
let buildable = ExprSyntax(
300+
#"""
301+
if true {
302+
assertionFailure("""
303+
Error validating child at index
304+
Node did not satisfy any node choice requirement.
305+
Validation failures:
306+
""")
307+
}
308+
"""#
309+
)
310+
311+
AssertBuildResult(
312+
buildable,
313+
#"""
314+
if true {
315+
assertionFailure("""
316+
Error validating child at index
317+
Node did not satisfy any node choice requirement.
318+
Validation failures:
319+
""")
320+
}
321+
"""#
322+
)
323+
}
324+
325+
func testMultiStringLiteralOnNewlineInIfExpr() {
326+
let buildable = ExprSyntax(
327+
#"""
328+
if true {
329+
assertionFailure(
330+
"""
331+
Error validating child at index
332+
Node did not satisfy any node choice requirement.
333+
Validation failures:
334+
"""
335+
)
336+
}
337+
"""#
338+
)
339+
340+
AssertBuildResult(
341+
buildable,
342+
#"""
343+
if true {
344+
assertionFailure(
345+
"""
346+
Error validating child at index
347+
Node did not satisfy any node choice requirement.
348+
Validation failures:
349+
"""
350+
)
351+
}
352+
"""#
353+
)
354+
}
173355
}

0 commit comments

Comments
 (0)