Skip to content

Commit 13ddedb

Browse files
committed
Add tests cases for failing multi line string
1 parent c1d6b43 commit 13ddedb

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

Tests/SwiftSyntaxBuilderTest/StringLiteralTests.swift

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,137 @@ final class StringLiteralTests: XCTestCase {
170170
"""#
171171
)
172172
}
173+
174+
func testMultiLineStringWithResultBuilder() {
175+
let buildable = StringLiteralExprSyntax(
176+
openQuote: .multilineStringQuoteToken(leadingTrivia: .newline, trailingTrivia: .newline),
177+
segments: StringLiteralSegmentsSyntax {
178+
StringSegmentSyntax(content: .stringSegment(#"Error validating child at index \(index) of \(nodeKind):"#), trailingTrivia: .newline)
179+
StringSegmentSyntax(content: .stringSegment(#"Node did not satisfy any node choice requirement."#), trailingTrivia: .newline)
180+
StringSegmentSyntax(content: .stringSegment(#"Validation failures:"#), trailingTrivia: .newline)
181+
StringSegmentSyntax(content: .stringSegment(#"\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))"#))
182+
},
183+
closeQuote: .multilineStringQuoteToken(leadingTrivia: .newline, trailingTrivia: .newline)
184+
)
185+
186+
AssertBuildResult(
187+
buildable,
188+
#"""
189+
Error validating child at index \(index) of \(nodeKind):
190+
Node did not satisfy any node choice requirement.
191+
Validation failures:
192+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n"))
193+
"""#
194+
)
195+
}
196+
197+
func testMultiLineStringWithFunctions() {
198+
let buildable = StringLiteralExprSyntax(
199+
openQuote: .multilineStringQuoteToken(trailingTrivia: .newline),
200+
content:
201+
#"""
202+
assertionFailure("""
203+
Error validating child at index \(index) of \(nodeKind):
204+
Node did not satisfy any node choice requirement.
205+
Validation failures:
206+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n") )
207+
""", file: file, line: line)
208+
"""#
209+
,
210+
closeQuote: .multilineStringQuoteToken(leadingTrivia: .newline)
211+
)
212+
213+
AssertBuildResult(
214+
buildable,
215+
##"""
216+
#"""
217+
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)
218+
"""#
219+
"""##
220+
221+
)
222+
}
223+
224+
func testMultiStringLiteralInExpr() {
225+
let buildable = ExprSyntax(
226+
#"""
227+
assertionFailure("""
228+
Error validating child at index \(index) of \(nodeKind):
229+
Node did not satisfy any node choice requirement.
230+
Validation failures:
231+
\(nonNilErrors.map({ "- \($0.description)" }).joined(separator: "\n") )
232+
""", file: file, line: line)
233+
"""#
234+
)
235+
236+
AssertBuildResult(
237+
buildable,
238+
#"""
239+
assertionFailure("""
240+
Error validating child at index \(index) of \(nodeKind):
241+
Node did not satisfy any node choice requirement.
242+
Validation failures:
243+
\(nonNilErrors.map( { "- \($0.description)" }).joined(separator: "\n") )
244+
""", file: file, line: line)
245+
"""#
246+
)
247+
}
248+
249+
func testMultiStringLiteralInIfExpr() {
250+
let buildable = ExprSyntax(
251+
#"""
252+
if nonNilErrors.count == errors.count {
253+
assertionFailure("""
254+
Error validating child at index
255+
Node did not satisfy any node choice requirement.
256+
Validation failures:
257+
""")
258+
}
259+
"""#
260+
)
261+
262+
AssertBuildResult(
263+
buildable,
264+
#"""
265+
if nonNilErrors.count == errors.count {
266+
assertionFailure("""
267+
Error validating child at index
268+
Node did not satisfy any node choice requirement.
269+
Validation failures:
270+
""")
271+
}
272+
"""#
273+
)
274+
}
275+
276+
func testMultiStringLiteralOnNewlineInIfExpr() {
277+
let buildable = ExprSyntax(
278+
#"""
279+
if true {
280+
assertionFailure(
281+
"""
282+
Error validating child at index
283+
Node did not satisfy any node choice requirement.
284+
Validation failures:
285+
"""
286+
)
287+
}
288+
"""#
289+
)
290+
291+
AssertBuildResult(
292+
buildable,
293+
#"""
294+
if true {
295+
assertionFailure(
296+
"""
297+
Error validating child at index
298+
Node did not satisfy any node choice requirement.
299+
Validation failures:
300+
"""
301+
)
302+
}
303+
"""#
304+
)
305+
}
173306
}

0 commit comments

Comments
 (0)