Skip to content

Commit

Permalink
Add Sendable test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshiki-tsukada committed Dec 21, 2024
1 parent de37c38 commit 8ea114a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: """
Expand Down

0 comments on commit 8ea114a

Please sign in to comment.