@@ -143,6 +143,102 @@ final class CommaTests: PrettyPrintTestCase {
143143 assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
144144 }
145145
146+ func testArrayWithCommentCommasPresentEnabled( ) {
147+ let input =
148+ """
149+ let MyCollection = [
150+ 1,
151+ 2 // some comment
152+ ]
153+
154+ """
155+
156+ let expected =
157+ """
158+ let MyCollection = [
159+ 1,
160+ 2, // some comment
161+ ]
162+
163+ """
164+
165+ var configuration = Configuration . forTesting
166+ configuration. multiElementCollectionTrailingCommas = true
167+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
168+ }
169+
170+ func testArrayWithCommentCommasPresentDisabled( ) {
171+ let input =
172+ """
173+ let MyCollection = [
174+ 1,
175+ 2 // some comment
176+ ]
177+
178+ """
179+
180+ let expected =
181+ """
182+ let MyCollection = [
183+ 1,
184+ 2 // some comment
185+ ]
186+
187+ """
188+
189+ var configuration = Configuration . forTesting
190+ configuration. multiElementCollectionTrailingCommas = false
191+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
192+ }
193+
194+ func testArrayWithTernaryOperatorAndCommentCommasPresentEnabled( ) {
195+ let input =
196+ """
197+ let MyCollection = [
198+ 1,
199+ true ? 1 : 2 // some comment
200+ ]
201+
202+ """
203+
204+ let expected =
205+ """
206+ let MyCollection = [
207+ 1,
208+ true ? 1 : 2, // some comment
209+ ]
210+
211+ """
212+
213+ var configuration = Configuration . forTesting
214+ configuration. multiElementCollectionTrailingCommas = true
215+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
216+ }
217+
218+ func testArrayWithTernaryOperatorAndCommentCommasPresentDisabled( ) {
219+ let input =
220+ """
221+ let MyCollection = [
222+ 1,
223+ true ? 1 : 2 // some comment
224+ ]
225+
226+ """
227+
228+ let expected =
229+ """
230+ let MyCollection = [
231+ 1,
232+ true ? 1 : 2 // some comment
233+ ]
234+
235+ """
236+
237+ var configuration = Configuration . forTesting
238+ configuration. multiElementCollectionTrailingCommas = false
239+ assertPrettyPrintEqual ( input: input, expected: expected, linelength: 40 , configuration: configuration)
240+ }
241+
146242 func testDictionaryCommasAbsentEnabled( ) {
147243 let input =
148244 """
0 commit comments