Skip to content

Commit e089934

Browse files
committed
Support InlineArray type sugar
1 parent e70ab31 commit e089934

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,12 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
17321732
return .visitChildren
17331733
}
17341734

1735+
override func visit(_ node: InlineArrayTypeSyntax) -> SyntaxVisitorContinueKind {
1736+
before(node.separator, tokens: .space)
1737+
after(node.separator, tokens: .space)
1738+
return .visitChildren
1739+
}
1740+
17351741
override func visit(_ node: TupleTypeSyntax) -> SyntaxVisitorContinueKind {
17361742
after(node.leftParen, tokens: .break(.open, size: 0), .open)
17371743
before(node.rightParen, tokens: .break(.close, size: 0), .close)

Tests/SwiftFormatTests/PrettyPrint/ArrayDeclTests.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,58 @@ final class ArrayDeclTests: PrettyPrintTestCase {
302302

303303
assertPrettyPrintEqual(input: input, expected: expected, linelength: 32)
304304
}
305+
306+
func testInlineArrayTypeSugar() {
307+
let input =
308+
"""
309+
let a: [3 of Int]
310+
let a: [[3 of Int]]
311+
let a: [[Int of 3]]
312+
let a: [_ of Int]
313+
let a: [Int of Int]
314+
let a: [@escaping () -> Int of Int]
315+
let a: [Int.Type of Int]
316+
let a: [sending P & Q of Int]
317+
let a: [(some P & Q) -> Int of Int]
318+
let a: [~P of Int]
319+
let a: [(Int, String) of Int]
320+
let a: [G<T> of Int]
321+
let a: [[3 of Int] of Int]
322+
let a: [[Int] of Int]
323+
let a: [_ of Int]
324+
let a: [_? of Int]
325+
let a: [_?of Int]
326+
let a: [_! of Int]
327+
let a: [_!of Int]
328+
let a: [Int?of Int]
329+
330+
"""
331+
332+
let expected =
333+
"""
334+
let a: [3 of Int]
335+
let a: [[3 of Int]]
336+
let a: [[Int of 3]]
337+
let a: [_ of Int]
338+
let a: [Int of Int]
339+
let a: [@escaping () -> Int of Int]
340+
let a: [Int.Type of Int]
341+
let a: [sending P & Q of Int]
342+
let a: [(some P & Q) -> Int of Int]
343+
let a: [~P of Int]
344+
let a: [(Int, String) of Int]
345+
let a: [G<T> of Int]
346+
let a: [[3 of Int] of Int]
347+
let a: [[Int] of Int]
348+
let a: [_ of Int]
349+
let a: [_? of Int]
350+
let a: [_? of Int]
351+
let a: [_! of Int]
352+
let a: [_! of Int]
353+
let a: [Int? of Int]
354+
355+
"""
356+
357+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40)
358+
}
305359
}

0 commit comments

Comments
 (0)