Skip to content

Commit 8032cf2

Browse files
authored
Merge pull request swiftlang#5 from allevato/sr-11113
Ensure a space after `@unknown` in a default case.
2 parents fe14b97 + a60cd8c commit 8032cf2

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
509509

510510
func visit(_ node: SwitchCaseSyntax) -> SyntaxVisitorContinueKind {
511511
before(node.firstToken, tokens: .newline)
512+
after(node.unknownAttr?.lastToken, tokens: .space)
512513
after(node.label.lastToken, tokens: .break(.reset, size: 0), .break(.open), .open)
513514
after(node.lastToken, tokens: .break(.close, size: 0), .close)
514515
return .visitChildren

Tests/SwiftFormatPrettyPrintTests/SwitchStmtTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,24 @@ public class SwitchStmtTests: PrettyPrintTestCase {
196196

197197
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
198198
}
199+
200+
public func testUnknownDefault() {
201+
let input =
202+
"""
203+
switch foo {
204+
@unknown default: bar()
205+
}
206+
"""
207+
208+
let expected =
209+
"""
210+
switch foo {
211+
@unknown default:
212+
bar()
213+
}
214+
215+
"""
216+
217+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20)
218+
}
199219
}

Tests/SwiftFormatPrettyPrintTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ extension SwitchStmtTests {
405405
("testSwitchCases", testSwitchCases),
406406
("testSwitchCompoundCases", testSwitchCompoundCases),
407407
("testSwitchValueBinding", testSwitchValueBinding),
408+
("testUnknownDefault", testUnknownDefault),
408409
]
409410
}
410411

0 commit comments

Comments
 (0)