Skip to content

Fix missing space in LabeledExprSyntax init #2291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2023
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
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ extension LabeledExprSyntax {
public init(label: String? = nil, expression: some ExprSyntaxProtocol) {
self.init(
label: label.map { .identifier($0) },
colon: label == nil ? nil : .colonToken(),
colon: label == nil ? nil : .colonToken(trailingTrivia: .space),
expression: expression
)
}
Expand Down
6 changes: 5 additions & 1 deletion Tests/SwiftSyntaxBuilderTest/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ func assertBuildResult<T: SyntaxProtocol>(
_ buildable: T,
_ expectedResult: String,
trimTrailingWhitespace: Bool = true,
format: Bool = true,
file: StaticString = #file,
line: UInt = #line
) {
var buildableDescription = buildable.formatted().description
var buildableDescription =
format
? buildable.formatted().description
: buildable.description
var expectedResult = expectedResult
if trimTrailingWhitespace {
buildableDescription = buildableDescription.trimmingTrailingWhitespace()
Expand Down
22 changes: 22 additions & 0 deletions Tests/SwiftSyntaxBuilderTest/LabeledExprSyntaxTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import SwiftSyntax
import SwiftSyntaxBuilder
import XCTest

final class LabeledExprSyntaxTests: XCTestCase {
func testLabeledExprSyntax() {
let syntax = LabeledExprSyntax(label: "arg", expression: NilLiteralExprSyntax())
assertBuildResult(syntax, "arg: nil", format: false)
}
}