From 8ea114aff5f613cc4b8d40c6271b0a32aad4e0db Mon Sep 17 00:00:00 2001 From: yoshiki-tsukada Date: Sun, 22 Dec 2024 00:31:02 +0900 Subject: [PATCH] Add Sendable test case --- .../Factories/UT_SpyFactory.swift | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift b/Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift index 02a5ddc..096dead 100644 --- a/Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift +++ b/Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift @@ -42,6 +42,56 @@ final class UT_SpyFactory: XCTestCase { ) } + func testDeclarationWithSendable() throws { + try assertProtocol( + withDeclaration: """ + protocol Service: Sendable { + func fetch() + } + """, + expectingClassDeclaration: """ + class ServiceSpy: Service, @unchecked Sendable { + init() { + } + var fetchCallsCount = 0 + var fetchCalled: Bool { + return fetchCallsCount > 0 + } + var fetchClosure: (() -> Void)? + func fetch() { + fetchCallsCount += 1 + fetchClosure?() + } + } + """ + ) + } + + func testDeclarationWithUncheckedSendable() throws { + try assertProtocol( + withDeclaration: """ + protocol Service: @unchecked Sendable { + func fetch() + } + """, + expectingClassDeclaration: """ + class ServiceSpy: Service, @unchecked Sendable { + init() { + } + var fetchCallsCount = 0 + var fetchCalled: Bool { + return fetchCallsCount > 0 + } + var fetchClosure: (() -> Void)? + func fetch() { + fetchCallsCount += 1 + fetchClosure?() + } + } + """ + ) + } + func testDeclarationArguments() throws { try assertProtocol( withDeclaration: """