Skip to content

Commit fe14b97

Browse files
authored
Merge pull request swiftlang#4 from allevato/sr-11112
Ensure a space after `case` in a `for case ... in` statement.
2 parents 2aeedb2 + fb293ff commit fe14b97

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
422422
func visit(_ node: ForInStmtSyntax) -> SyntaxVisitorContinueKind {
423423
after(node.labelColon, tokens: .space)
424424
after(node.forKeyword, tokens: .space)
425+
after(node.caseKeyword, tokens: .space)
425426
before(node.inKeyword, tokens: .break)
426427
after(node.inKeyword, tokens: .space)
427428

Tests/SwiftFormatPrettyPrintTests/ForInStmtTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,27 @@ public class ForInStmtTests: PrettyPrintTestCase {
163163

164164
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40)
165165
}
166+
167+
public func testForCase() {
168+
let input =
169+
"""
170+
for case let a as String in [] {
171+
let a = 123
172+
print(i)
173+
}
174+
"""
175+
176+
let expected =
177+
"""
178+
for case let a
179+
as String in []
180+
{
181+
let a = 123
182+
print(i)
183+
}
184+
185+
"""
186+
187+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20)
188+
}
166189
}

Tests/SwiftFormatPrettyPrintTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ extension ForInStmtTests {
175175
// to regenerate.
176176
static let __allTests__ForInStmtTests = [
177177
("testBasicForLoop", testBasicForLoop),
178+
("testForCase", testForCase),
178179
("testForLabels", testForLabels),
179180
("testForLoopFullWrap", testForLoopFullWrap),
180181
("testForWhereLoop", testForWhereLoop),

0 commit comments

Comments
 (0)