-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
Sendable
compliant protocols and classes (#254)
* Implemented inheritance of @unchecked Sendable for mock classes conforming to the Sendable protocol * Corrected syntax for inheritedTypes in template processing * Fixed CoW overhead issues * Removed unnecessary imports
- Loading branch information
Showing
9 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import MockoloFramework | ||
|
||
let sendableProtocol = """ | ||
/// \(String.mockAnnotation) | ||
public protocol SendableProtocol: Sendable { | ||
func update(arg: Int) -> String | ||
} | ||
""" | ||
|
||
let sendableProtocolMock = """ | ||
public class SendableProtocolMock: SendableProtocol, @unchecked Sendable { | ||
public init() { } | ||
public private(set) var updateCallCount = 0 | ||
public var updateHandler: ((Int) -> (String))? | ||
public func update(arg: Int) -> String { | ||
updateCallCount += 1 | ||
if let updateHandler = updateHandler { | ||
return updateHandler(arg) | ||
} | ||
return "" | ||
} | ||
} | ||
""" | ||
|
||
let uncheckedSendableClass = """ | ||
/// \(String.mockAnnotation) | ||
public class UncheckedSendableClass: @unchecked Sendable { | ||
func update(arg: Int) -> String | ||
} | ||
""" | ||
|
||
let uncheckedSendableClassMock = """ | ||
public class UncheckedSendableClassMock: UncheckedSendableClass, @unchecked Sendable { | ||
public init() { } | ||
private(set) var updateCallCount = 0 | ||
var updateHandler: ((Int) -> (String))? | ||
override func update(arg: Int) -> String { | ||
updateCallCount += 1 | ||
if let updateHandler = updateHandler { | ||
return updateHandler(arg) | ||
} | ||
return "" | ||
} | ||
} | ||
""" | ||
|
||
let confirmedSendableProtocol = """ | ||
public protocol SendableSendable: Sendable { | ||
func update(arg: Int) -> String | ||
} | ||
/// \(String.mockAnnotation) | ||
public protocol ConfirmedSendableProtocol: SendableSendable { | ||
} | ||
""" | ||
|
||
let confirmedSendableProtocolMock = """ | ||
public class ConfirmedSendableProtocolMock: ConfirmedSendableProtocol, @unchecked Sendable { | ||
public init() { } | ||
public private(set) var updateCallCount = 0 | ||
public var updateHandler: ((Int) -> (String))? | ||
public func update(arg: Int) -> String { | ||
updateCallCount += 1 | ||
if let updateHandler = updateHandler { | ||
return updateHandler(arg) | ||
} | ||
return "" | ||
} | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class SendableTests: MockoloTestCase { | ||
func testSendableProtocol() { | ||
verify(srcContent: sendableProtocol, | ||
dstContent: sendableProtocolMock) | ||
} | ||
|
||
func testUncheckedSendableClass() { | ||
verify(srcContent: uncheckedSendableClass, | ||
dstContent: uncheckedSendableClassMock, | ||
declType: .classType) | ||
} | ||
|
||
func testConfirmingSendableProtocol() { | ||
verify(srcContent: confirmedSendableProtocol, | ||
dstContent: confirmedSendableProtocolMock) | ||
} | ||
} |