@@ -75,6 +75,40 @@ public class SwitchStmtTests: PrettyPrintTestCase {
75
75
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 35 )
76
76
}
77
77
78
+ public func testSwitchCompoundCases( ) {
79
+ let input =
80
+ """
81
+ switch someChar {
82
+ case " a " :
83
+ print( " a " )
84
+ case " b " , " c " :
85
+ print( " bc " )
86
+ case " d " , " e " , " f " , " g " , " h " :
87
+ print( " defgh " )
88
+ default:
89
+ print( " default " )
90
+ }
91
+ """
92
+
93
+ let expected =
94
+ """
95
+ switch someChar {
96
+ case " a " :
97
+ print( " a " )
98
+ case " b " , " c " :
99
+ print( " bc " )
100
+ case " d " , " e " , " f " ,
101
+ " g " , " h " :
102
+ print( " defgh " )
103
+ default:
104
+ print( " default " )
105
+ }
106
+
107
+ """
108
+
109
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 20 )
110
+ }
111
+
78
112
public func testNestedSwitch( ) {
79
113
let input =
80
114
"""
@@ -109,4 +143,81 @@ public class SwitchStmtTests: PrettyPrintTestCase {
109
143
110
144
assertPrettyPrintEqual ( input: input, expected: expected, linelength: 35 )
111
145
}
146
+
147
+ public func testSwitchValueBinding( ) {
148
+ let input =
149
+ """
150
+ switch someValue {
151
+ case let thisval:
152
+ let c = 123
153
+ var d = 456 + thisval
154
+ }
155
+ switch somePoint {
156
+ case (let x, 0):
157
+ print(x)
158
+ case (0, let y):
159
+ print(y)
160
+ case let (x, y):
161
+ print(x + y)
162
+ }
163
+ switch anotherPoint {
164
+ case (let distance, 0), (0, let distance):
165
+ print(distance)
166
+ case (let distance, 0), (0, let distance), (let distance, 10):
167
+ print(distance)
168
+ default:
169
+ print( " A message " )
170
+ }
171
+ switch pointy {
172
+ case let (x, y) where x == y:
173
+ print( " Equal " )
174
+ case let (x, y) where x == -y:
175
+ print( " Opposite sign " )
176
+ case let (reallyLongName, anotherLongName) where reallyLongName == -anotherLongName:
177
+ print( " Opposite sign " )
178
+ case let (x, y):
179
+ print( " Arbitrary value " )
180
+ }
181
+ """
182
+
183
+ let expected =
184
+ """
185
+ switch someValue {
186
+ case let thisval:
187
+ let c = 123
188
+ var d = 456 + thisval
189
+ }
190
+ switch somePoint {
191
+ case (let x, 0):
192
+ print(x)
193
+ case (0, let y):
194
+ print(y)
195
+ case let (x, y):
196
+ print(x + y)
197
+ }
198
+ switch anotherPoint {
199
+ case (let distance, 0), (0, let distance):
200
+ print(distance)
201
+ case (let distance, 0), (0, let distance),
202
+ (let distance, 10):
203
+ print(distance)
204
+ default:
205
+ print( " A message " )
206
+ }
207
+ switch pointy {
208
+ case let (x, y) where x == y:
209
+ print( " Equal " )
210
+ case let (x, y) where x == -y:
211
+ print( " Opposite sign " )
212
+ case let (reallyLongName, anotherLongName)
213
+ where reallyLongName == -anotherLongName:
214
+ print( " Opposite sign " )
215
+ case let (x, y):
216
+ print( " Arbitrary value " )
217
+ }
218
+
219
+ """
220
+
221
+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 45 )
222
+ }
112
223
}
0 commit comments