Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite1cd715

Browse files
authored
Merge pull request#1043 from TTOzzi/inline-array-type-sugar
Add support for InlineArray type sugar
2 parentsbd5a712 +c2c0c4a commite1cd715

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

‎Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift‎

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

1735+
overridefunc visit(_ node:InlineArrayTypeSyntax)->SyntaxVisitorContinueKind{
1736+
after(node.leftSquare, tokens:.break(.open, size:0),.open)
1737+
before(node.separator, tokens:.space)
1738+
after(node.separator, tokens:.break)
1739+
before(node.rightSquare, tokens:.break(.close, size:0),.close)
1740+
return.visitChildren
1741+
}
1742+
17351743
overridefunc visit(_ node:TupleTypeSyntax)->SyntaxVisitorContinueKind{
17361744
after(node.leftParen, tokens:.break(.open, size:0),.open)
17371745
before(node.rightParen, tokens:.break(.close, size:0),.close)

‎Tests/SwiftFormatTests/PrettyPrint/ArrayDeclTests.swift‎

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

303303
assertPrettyPrintEqual(input: input, expected: expected, linelength:32)
304304
}
305+
306+
func testInlineArrayTypeSugar(){
307+
letinput=
308+
"""
309+
let a: [3 of Int]
310+
let a: [[3 of Int]]
311+
let a: [3 of [3 of Int]]
312+
let a: [n of Int]
313+
let fiveIntegers: [5 of _] = .init(repeating: 99)
314+
let fourBytes: [_ of Int8] = [1, 2, 3, 4]
315+
let fourIntegers: [_ of _] = [1, 2, 3, 4]
316+
let fiveDoubles = [5 of _](repeating: 1.23)
317+
318+
"""
319+
320+
letexpected=
321+
"""
322+
let a: [3 of Int]
323+
let a: [[3 of Int]]
324+
let a: [3 of [3 of Int]]
325+
let a: [n of Int]
326+
let fiveIntegers: [5 of _] = .init(repeating: 99)
327+
let fourBytes: [_ of Int8] = [1, 2, 3, 4]
328+
let fourIntegers: [_ of _] = [1, 2, 3, 4]
329+
let fiveDoubles = [5 of _](repeating: 1.23)
330+
331+
"""
332+
333+
assertPrettyPrintEqual(input: input, expected: expected, linelength:80)
334+
}
335+
336+
func testInlineArrayTypeSugarWhenLineLengthExceeded(){
337+
letinput=
338+
"""
339+
let a: [3 of VeryLongGenericTypeNameThatCausesWrapping]
340+
let a: [3 of [3 of VeryLongGenericTypeNameThatCausesWrapping]]
341+
let a = [3 of VeryLongGenericTypeNameThatCausesWrapping](repeating: foo)
342+
343+
"""
344+
345+
letexpected=
346+
"""
347+
let a:
348+
[
349+
3 of
350+
VeryLongGenericTypeNameThatCausesWrapping
351+
]
352+
let a:
353+
[
354+
3 of
355+
[
356+
3 of
357+
VeryLongGenericTypeNameThatCausesWrapping
358+
]
359+
]
360+
let a =
361+
[
362+
3 of
363+
VeryLongGenericTypeNameThatCausesWrapping
364+
](
365+
repeating:
366+
foo
367+
)
368+
369+
"""
370+
371+
assertPrettyPrintEqual(input: input, expected: expected, linelength:5)
372+
}
305373
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp