Skip to content

Commit 326d6f1

Browse files
authored
Merge pull request #94 from Matejkob/more-tests
Add more unit tests to existential and opaque types
2 parents 8c8e265 + c889929 commit 326d6f1

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Examples/Sources/ViewModel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ protocol ServiceProtocol {
1111
func initialize(name: String, _ secondName: String?)
1212
func fetchConfig(arg: UInt8) async throws -> [String: String]
1313
func fetchData(_ name: (String, count: Int)) async -> (() -> Void)
14+
func save(name: any Codable, surname: any Codable)
15+
func insert(name: (any Codable)?, surname: (any Codable)?)
16+
func append(name: (any Codable) -> (any Codable)?)
1417
}
1518

1619
final class ViewModel {

Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,87 @@ final class UT_SpyFactory: XCTestCase {
9292
)
9393
}
9494

95+
func testDeclarationOptionalExistentialTypeArguments() throws {
96+
try assertProtocol(
97+
withDeclaration: """
98+
protocol ViewModelProtocol {
99+
func foo(model: (any ModelProtocol)?)
100+
}
101+
""",
102+
expectingClassDeclaration: """
103+
class ViewModelProtocolSpy: ViewModelProtocol {
104+
var fooModelCallsCount = 0
105+
var fooModelCalled: Bool {
106+
return fooModelCallsCount > 0
107+
}
108+
var fooModelReceivedModel: (any ModelProtocol)?
109+
var fooModelReceivedInvocations: [(any ModelProtocol)?] = []
110+
var fooModelClosure: (((any ModelProtocol)?) -> Void)?
111+
func foo(model: (any ModelProtocol)?) {
112+
fooModelCallsCount += 1
113+
fooModelReceivedModel = (model)
114+
fooModelReceivedInvocations.append((model))
115+
fooModelClosure?(model)
116+
}
117+
}
118+
"""
119+
)
120+
}
121+
122+
func testDeclarationOpaqueTypeArgument() throws {
123+
try assertProtocol(
124+
withDeclaration: """
125+
protocol ViewModelProtocol {
126+
func foo(model: some ModelProtocol)
127+
}
128+
""",
129+
expectingClassDeclaration: """
130+
class ViewModelProtocolSpy: ViewModelProtocol {
131+
var fooModelCallsCount = 0
132+
var fooModelCalled: Bool {
133+
return fooModelCallsCount > 0
134+
}
135+
var fooModelReceivedModel: (some ModelProtocol)?
136+
var fooModelReceivedInvocations: [some ModelProtocol] = []
137+
var fooModelClosure: ((some ModelProtocol) -> Void)?
138+
func foo(model: some ModelProtocol) {
139+
fooModelCallsCount += 1
140+
fooModelReceivedModel = (model)
141+
fooModelReceivedInvocations.append((model))
142+
fooModelClosure?(model)
143+
}
144+
}
145+
"""
146+
)
147+
}
148+
149+
func testDeclarationOptionalOpaqueTypeArgument() throws {
150+
try assertProtocol(
151+
withDeclaration: """
152+
protocol ViewModelProtocol {
153+
func foo(model: (some ModelProtocol)?)
154+
}
155+
""",
156+
expectingClassDeclaration: """
157+
class ViewModelProtocolSpy: ViewModelProtocol {
158+
var fooModelCallsCount = 0
159+
var fooModelCalled: Bool {
160+
return fooModelCallsCount > 0
161+
}
162+
var fooModelReceivedModel: (some ModelProtocol)?
163+
var fooModelReceivedInvocations: [(some ModelProtocol)?] = []
164+
var fooModelClosure: (((some ModelProtocol)?) -> Void)?
165+
func foo(model: (some ModelProtocol)?) {
166+
fooModelCallsCount += 1
167+
fooModelReceivedModel = (model)
168+
fooModelReceivedInvocations.append((model))
169+
fooModelClosure?(model)
170+
}
171+
}
172+
"""
173+
)
174+
}
175+
95176
func testDeclarationEscapingAutoClosureArgument() throws {
96177
try assertProtocol(
97178
withDeclaration: """

0 commit comments

Comments
 (0)