Skip to content

Commit 9ab323e

Browse files
committed
[Tests] Add a few tests to make sure that empty collection init rule doesn't affect other cases
1 parent 2ca2c46 commit 9ab323e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

Tests/SwiftFormatTests/Rules/AlwaysUseLiteralForEmptyCollectionInitTests.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
2525
subscript(_: [A] = 7️⃣[A](), x: [(Int, B)] = 8️⃣[(Int, B)]()) {
2626
}
2727
}
28+
29+
// All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
30+
do {
31+
let _ = [Int](repeating: 0, count: 10)
32+
let _: [Int] = [Int](repeating: 0, count: 10)
33+
34+
func testDefault(_ x: [String] = [String](repeating: "a", count: 42)) {
35+
}
36+
37+
class TestSubscript {
38+
subscript(_: Int = 42, x: [(Int, B)] = [(Int, B)](repeating: (0, B()), count: 1)) {
39+
}
40+
}
41+
}
2842
""",
2943
expected: """
3044
public struct Test {
@@ -45,6 +59,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
4559
subscript(_: [A] = [], x: [(Int, B)] = []) {
4660
}
4761
}
62+
63+
// All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
64+
do {
65+
let _ = [Int](repeating: 0, count: 10)
66+
let _: [Int] = [Int](repeating: 0, count: 10)
67+
68+
func testDefault(_ x: [String] = [String](repeating: "a", count: 42)) {
69+
}
70+
71+
class TestSubscript {
72+
subscript(_: Int = 42, x: [(Int, B)] = [(Int, B)](repeating: (0, B()), count: 1)) {
73+
}
74+
}
75+
}
4876
""",
4977
findings: [
5078
FindingSpec("1️⃣", message: "replace '[Int]()' with ': [Int] = []'"),
@@ -81,6 +109,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
81109
subscript(_: [A: Int] = 7️⃣[A: Int](), x: [(Int, B): String] = 8️⃣[(Int, B): String]()) {
82110
}
83111
}
112+
113+
// All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
114+
do {
115+
let _ = [String: Int](minimumCapacity: 42)
116+
let _: [String: Int] = [String: Int](minimumCapacity: 42)
117+
118+
func testDefault(_ x: [Int: String] = [String](minimumCapacity: 1)) {
119+
}
120+
121+
class TestSubscript {
122+
subscript(_: Int = 42, x: [String: (Int, B)] = [String: (Int, B)](minimumCapacity: 2)) {
123+
}
124+
}
125+
}
84126
""",
85127
expected: """
86128
public struct Test {
@@ -101,6 +143,20 @@ final class AlwaysUseLiteralForEmptyCollectionInitTests: LintOrFormatRuleTestCas
101143
subscript(_: [A: Int] = [:], x: [(Int, B): String] = [:]) {
102144
}
103145
}
146+
147+
// All of the examples in this block could be re-written to use leading-dot syntax: `.init(...)`
148+
do {
149+
let _ = [String: Int](minimumCapacity: 42)
150+
let _: [String: Int] = [String: Int](minimumCapacity: 42)
151+
152+
func testDefault(_ x: [Int: String] = [String](minimumCapacity: 1)) {
153+
}
154+
155+
class TestSubscript {
156+
subscript(_: Int = 42, x: [String: (Int, B)] = [String: (Int, B)](minimumCapacity: 2)) {
157+
}
158+
}
159+
}
104160
""",
105161
findings: [
106162
FindingSpec("1️⃣", message: "replace '[Int: String]()' with ': [Int: String] = [:]'"),

0 commit comments

Comments
 (0)