Skip to content

Commit 2c6caf2

Browse files
Refactor mock array extensions
1 parent 0224025 commit 2c6caf2

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

Tests/NodesGeneratorTests/Support/Array.swift

+25-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ extension Array where Element == String {
1414
internal static func mock(with identifier: String, count: Int) -> Self {
1515
guard count > 0
1616
else { return [] }
17-
guard count > 1
18-
else { return ["<\(identifier)>"] }
19-
return (1...count).map { "<\(identifier)\($0)>" }
17+
return switch count {
18+
case 1:
19+
[
20+
"<\(identifier)>"
21+
]
22+
default:
23+
(1...count).map { index in
24+
"<\(identifier)\(index)>"
25+
}
26+
}
2027
}
2128
}
2229

@@ -25,10 +32,21 @@ extension Array where Element == Config.Variable {
2532
internal static func mock(with identifier: String, count: Int) -> Self {
2633
guard count > 0
2734
else { return [] }
28-
guard count > 1
29-
else { return [Config.Variable(name: "<\(identifier)Name>", type: "<\(identifier)Type>")] }
30-
return (1...count).map { count in
31-
Config.Variable(name: "<\(identifier)Name\(count)>", type: "<\(identifier)Type\(count)>")
35+
return switch count {
36+
case 1:
37+
[
38+
Config.Variable(
39+
name: "<\(identifier)Name>",
40+
type: "<\(identifier)Type>"
41+
)
42+
]
43+
default:
44+
(1...count).map { index in
45+
Config.Variable(
46+
name: "<\(identifier)Name\(index)>",
47+
type: "<\(identifier)Type\(index)>"
48+
)
49+
}
3250
}
3351
}
3452
}

0 commit comments

Comments
 (0)