Skip to content

Commit 126e3df

Browse files
committed
Fix missing newline for opening quote for multilines strings
1 parent 75252f3 commit 126e3df

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ open class BasicFormat: SyntaxRewriter {
178178
}
179179

180180
switch (first?.tokenKind, second?.tokenKind) {
181-
case (.multilineStringQuote, .multilineStringQuote),
181+
case (.multilineStringQuote, .backslash),
182+
(.multilineStringQuote, .multilineStringQuote),
182183
(.multilineStringQuote, .stringSegment),
183184
(.stringSegment, .multilineStringQuote),
184185
(.rightParen, .multilineStringQuote):

Tests/SwiftSyntaxBuilderTest/StringLiteralExprSyntaxTests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,44 @@ final class StringLiteralExprSyntaxTests: XCTestCase {
334334
"""#
335335
)
336336
}
337+
338+
func testMultiStringOpeningQuote() {
339+
assertBuildResult(
340+
StringLiteralExprSyntax(openQuote: .multilineStringQuoteToken(), content: "a", closeQuote: .multilineStringQuoteToken()),
341+
#"""
342+
"""
343+
a
344+
"""
345+
"""#
346+
)
347+
348+
assertBuildResult(
349+
StringLiteralExprSyntax(
350+
openQuote: .multilineStringQuoteToken(),
351+
segments: StringLiteralSegmentsSyntax {
352+
.expressionSegment(
353+
ExpressionSegmentSyntax(
354+
expressions: TupleExprElementListSyntax {
355+
TupleExprElementSyntax(
356+
expression: StringLiteralExprSyntax(
357+
openQuote: .multilineStringQuoteToken(),
358+
content: "a",
359+
closeQuote: .multilineStringQuoteToken()
360+
)
361+
)
362+
}
363+
)
364+
)
365+
},
366+
closeQuote: .multilineStringQuoteToken()
367+
),
368+
#"""
369+
"""
370+
\("""
371+
a
372+
""")
373+
"""
374+
"""#
375+
)
376+
}
337377
}

0 commit comments

Comments
 (0)