File tree 2 files changed +40
-0
lines changed
Sources/SwiftFormatPrettyPrint
Tests/SwiftFormatPrettyPrintTests
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,12 @@ private final class TokenStreamCreator: SyntaxVisitor {
765
765
}
766
766
767
767
override func visit( _ node: TernaryExprSyntax ) {
768
+ before ( node. conditionExpression. firstToken, tokens: . open( . inconsistent, 2 ) )
769
+ before ( node. questionMark, tokens: . break)
770
+ after ( node. questionMark, tokens: . space)
771
+ before ( node. colonMark, tokens: . break)
772
+ after ( node. colonMark, tokens: . space)
773
+ after ( node. secondChoice. lastToken, tokens: . close)
768
774
super. visit ( node)
769
775
}
770
776
Original file line number Diff line number Diff line change
1
+ public class TernaryExprTests : PrettyPrintTestCase {
2
+ public func testTernaryExprs( ) {
3
+ let input =
4
+ """
5
+ let x = a ? b : c
6
+ let y = a ?b:c
7
+ let z = a
8
+ ? b
9
+ : c
10
+ let reallyLongName = a ? longTruePart : longFalsePart
11
+ let reallyLongName = reallyLongCondition ? reallyLongTruePart : reallyLongFalsePart
12
+ let reallyLongName = reallyLongCondition ? reallyReallyReallyLongTruePart : reallyLongFalsePart
13
+ """
14
+
15
+ let expected =
16
+ """
17
+ let x = a ? b : c
18
+ let y = a ? b : c
19
+ let z = a ? b : c
20
+ let reallyLongName =
21
+ a ? longTruePart : longFalsePart
22
+ let reallyLongName =
23
+ reallyLongCondition ? reallyLongTruePart
24
+ : reallyLongFalsePart
25
+ let reallyLongName =
26
+ reallyLongCondition
27
+ ? reallyReallyReallyLongTruePart
28
+ : reallyLongFalsePart
29
+
30
+ """
31
+
32
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 45 )
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments