Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
// Looks up the correct break kind based on prior context.
let breakKind = pendingMultilineStringBreakKinds[node, default: .same]
after(node.openQuote, tokens: .break(breakKind, size: 0, newlines: .hard(count: 1)))
before(node.closeQuote, tokens: .break(breakKind, newlines: .hard(count: 1)))
if !node.segments.isEmpty {
before(node.closeQuote, tokens: .break(breakKind, newlines: .hard(count: 1)))
}
}
return .visitChildren
}
Expand Down
41 changes: 41 additions & 0 deletions Tests/SwiftFormatPrettyPrintTests/StringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ final class StringTests: PrettyPrintTestCase {

assertPrettyPrintEqual(input: input, expected: expected, linelength: 20)
}

func testLeadingMultilineStringsInOtherExpressions() {
// The stacked indentation behavior needs to drill down into different node types to find the
// leftmost multiline string literal. This makes sure that we cover various cases.
Expand Down Expand Up @@ -417,4 +418,44 @@ final class StringTests: PrettyPrintTestCase {
"""#
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 100)
}

func testEmptyMultilineStrings() {
let input =
##"""
let x = """
"""
let y =
"""
"""
let x = #"""
"""#
let y =
#"""
"""#
"""##

assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 20)
}

func testOnlyBlankLinesMultilineStrings() {
let input =
##"""
let x = """

"""
let y =
"""

"""
let x = #"""

"""#
let y =
#"""

"""#
"""##

assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 20)
}
}