Skip to content

Commit 9a7c7e2

Browse files
committed
Remove trailing space from : after SwitchCaseSyntax.Label.*
1 parent 3fd88fd commit 9a7c7e2

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public let EXPR_NODES: [Node] = [
456456
Child(name: "CaseItems",
457457
kind: .collection(kind: "CaseItemList", collectionElementName: "CaseItem")),
458458
Child(name: "Colon",
459-
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
459+
kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false))
460460
]),
461461

462462
Node(name: "SwitchDefaultLabel",
@@ -466,7 +466,7 @@ public let EXPR_NODES: [Node] = [
466466
Child(name: "DefaultKeyword",
467467
kind: .token(choices: [.keyword(text: "default")])),
468468
Child(name: "Colon",
469-
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
469+
kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false))
470470
]),
471471

472472
Node(name: "CaseItem",

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ open class BasicFormat: SyntaxRewriter {
186186
return false
187187
case \DynamicReplacementArgumentsSyntax.forLabel:
188188
return false
189+
case \SwitchCaseLabelSyntax.colon:
190+
return false
191+
case \SwitchDefaultLabelSyntax.colon:
192+
return false
189193
case \TryExprSyntax.questionOrExclamationMark:
190194
return true
191195
default:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
import SwiftSyntax
15+
import SwiftSyntaxBuilder
16+
17+
final class SwitchCaseLabelSyntaxTests: XCTestCase {
18+
func testSwitchCaseLabelSyntax() {
19+
let testCases: [UInt: (SwitchCaseSyntax, String)] = [
20+
#line: (
21+
SwitchCaseSyntax("default:") {
22+
StmtSyntax("return nil")
23+
24+
},
25+
"""
26+
default:
27+
return nil
28+
"""
29+
),
30+
#line: (
31+
SwitchCaseSyntax("case .foo:") {
32+
StmtSyntax("return nil")
33+
34+
},
35+
"""
36+
case .foo:
37+
return nil
38+
"""
39+
),
40+
]
41+
42+
for (line, testCase) in testCases {
43+
let (builder, expected) = testCase
44+
AssertBuildResult(builder, expected, trimTrailingWhitespace: false, line: line)
45+
}
46+
}
47+
}

gyb_syntax_support/ExprNodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,14 @@
347347
Child('CaseKeyword', kind='KeywordToken', token_choices=['KeywordToken|case']),
348348
Child('CaseItems', kind='CaseItemList',
349349
collection_element_name='CaseItem'),
350-
Child('Colon', kind='ColonToken'),
350+
Child('Colon', kind='ColonToken', requires_trailing_space=False),
351351
]),
352352

353353
# switch-default-label -> 'default' ':'
354354
Node('SwitchDefaultLabel', name_for_diagnostics=None, kind='Syntax',
355355
children=[
356356
Child('DefaultKeyword', kind='KeywordToken', token_choices=['KeywordToken|default']),
357-
Child('Colon', kind='ColonToken'),
357+
Child('Colon', kind='ColonToken', requires_trailing_space=False),
358358
]),
359359

360360
# case-item -> pattern where-clause? ','?

0 commit comments

Comments
 (0)