Skip to content

Commit 31aba31

Browse files
authored
Merge pull request swiftlang#135 from kitasuke/SR-10241_bug_fix
Remove redundant leading/trailing trivia from StringLiteralExpr
2 parents a0ada01 + 7e2c625 commit 31aba31

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Sources/SwiftSyntax/SyntaxFactory.swift.gyb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ public enum SyntaxFactory {
199199
public static func makeStringLiteralExpr(_ text: String,
200200
leadingTrivia: Trivia = [],
201201
trailingTrivia: Trivia = []) -> StringLiteralExprSyntax {
202-
let string = makeStringSegment(text,
203-
leadingTrivia: leadingTrivia,
204-
trailingTrivia: trailingTrivia)
202+
let string = makeStringSegment(text)
205203
let segment = makeStringSegment(content: string)
206204
let segments = makeStringLiteralSegments([segment])
207205
let openQuote = makeStringQuoteToken(leadingTrivia: leadingTrivia)

Tests/SwiftSyntaxTest/SyntaxFactory.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
2424
("testFunctionCallSyntaxBuilder", testFunctionCallSyntaxBuilder),
2525
("testWithOptionalChild", testWithOptionalChild),
2626
("testUnknownSyntax", testUnknownSyntax),
27+
("testMakeStringLiteralExpr", testMakeStringLiteralExpr),
2728
]
2829

2930
public func testGenerated() {
@@ -160,4 +161,16 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
160161
XCTAssertNoThrow(try SyntaxVerifier.verify(expr))
161162
XCTAssertThrowsError(try SyntaxVerifier.verify(unknown))
162163
}
164+
165+
public func testMakeStringLiteralExpr() {
166+
let expr = SyntaxFactory.makeStringLiteralExpr(
167+
"Hello, world!",
168+
leadingTrivia: .init(pieces: [.lineComment("// hello"), .newlines(1)])
169+
)
170+
let expected = """
171+
// hello
172+
"Hello, world!"
173+
"""
174+
XCTAssertEqual(expr.description, expected)
175+
}
163176
}

0 commit comments

Comments
 (0)