Skip to content

Commit 8e87fda

Browse files
authored
Merge pull request swiftlang#188 from google/format-spaces-in-single-member-types
Ensure a space inside braces in a single member type decl.
2 parents 039519a + ce79be8 commit 8e87fda

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ private final class TokenStreamCreator: SyntaxVisitor {
172172
if !members.members.isEmpty {
173173
after(
174174
members.leftBrace,
175-
tokens: .close, .close, .break(size: 0, offset: 2), .open(.consistent, 0)
175+
tokens: .close, .close, .break(size: 1, offset: 2), .open(.consistent, 0)
176176
)
177-
before(members.rightBrace, tokens: .break(size: 0, offset: -2), .close)
177+
before(members.rightBrace, tokens: .break(size: 1, offset: -2), .close)
178178
} else {
179179
// The size-0 break in the empty case allows for a break between the braces in the rare event
180180
// that the declaration would be exactly the column limit + 1.

Tests/SwiftFormatPrettyPrintTests/ClassDeclTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,9 @@ public class ClassDeclTests: PrettyPrintTestCase {
290290
"""
291291
assertPrettyPrintEqual(input: input, expected: wrapped, linelength: 11)
292292
}
293+
294+
public func testOneMemberClass() {
295+
let input = "class Foo { var bar: Int }"
296+
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
297+
}
293298
}

Tests/SwiftFormatPrettyPrintTests/EnumDeclTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,9 @@ public class EnumDeclTests: PrettyPrintTestCase {
369369
"""
370370
assertPrettyPrintEqual(input: input, expected: wrapped, linelength: 10)
371371
}
372+
373+
public func testOneMemberEnum() {
374+
let input = "enum Foo { var bar: Int }"
375+
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
376+
}
372377
}

Tests/SwiftFormatPrettyPrintTests/ExtensionDeclTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,9 @@ public class ExtensionDeclTests: PrettyPrintTestCase {
245245
"""
246246
assertPrettyPrintEqual(input: input, expected: wrapped, linelength: 15)
247247
}
248+
249+
public func testOneMemberExtension() {
250+
let input = "extension Foo { var bar: Int { return 0 } }"
251+
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
252+
}
248253
}

Tests/SwiftFormatPrettyPrintTests/ProtocolDeclTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,9 @@ public class ProtocolDeclTests: PrettyPrintTestCase {
238238
"""
239239
assertPrettyPrintEqual(input: input, expected: wrapped, linelength: 14)
240240
}
241+
242+
public func testOneMemberProtocol() {
243+
let input = "protocol Foo { var bar: Int { get } }"
244+
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
245+
}
241246
}

Tests/SwiftFormatPrettyPrintTests/StructDeclTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,9 @@ public class StructDeclTests: PrettyPrintTestCase {
290290
"""
291291
assertPrettyPrintEqual(input: input, expected: wrapped, linelength: 12)
292292
}
293+
294+
public func testOneMemberStruct() {
295+
let input = "struct Foo { var bar: Int }"
296+
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
297+
}
293298
}

0 commit comments

Comments
 (0)