Skip to content

Commit

Permalink
chore: add unchecked Sendable conformance to AutoMockable
Browse files Browse the repository at this point in the history
  • Loading branch information
nekrich committed Aug 1, 2024
1 parent 81033ec commit 2a26b88
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Templates/Templates/AutoMockable.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ import {{ import }}
{% endif %}
{%- endmacro %}

{% macro extractRequiredProtocolConformance type -%}
{% if type.based.Sendable %}, @unchecked Sendable{% endif %}
{%- endmacro %}

{% for type in types.protocols where type.based.AutoMockable or type|annotated:"AutoMockable" %}{% if type.name != "AutoMockable" %}
{% call accessLevel type.accessLevel %}class {{ type.name }}Mock{% set generics %}{% call extractProtocolCompositionFromAssociatedTypes type %}{% endset %}{{ generics | replace:",>",">"}}: {{ type.name }} {%- set requirements -%}{% call extractProtocolRequirementsFromType type %}{%- endset -%} {{ requirements|replace:",{","{"|replace:"{"," {" }}
{% call accessLevel type.accessLevel %}class {{ type.name }}Mock{% set generics %}{% call extractProtocolCompositionFromAssociatedTypes type %}{% endset %}{{ generics | replace:",>",">"}}: {{ type.name }}{% call extractRequiredProtocolConformance type %} {%- set requirements -%}{% call extractProtocolRequirementsFromType type %}{%- endset -%} {{ requirements|replace:",{","{"|replace:"{"," {" }}
{% for associatedType in type.associatedTypes|sortedValuesByKeys %}
{% if associatedType.type.kind == nil or not associatedType.type.kind|contains:"protocol" %}
typealias {{ associatedType.name }} = {% if associatedType.type != nil %}{{ associatedType.type.name }}{% elif associatedType.typeName != nil %}{{ associatedType.typeName.name }}{% else %}Any{% endif %}
Expand Down
12 changes: 12 additions & 0 deletions Templates/Tests/Context/AutoMockable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,15 @@ protocol TestProtocol {

func getValue6() -> Value6
}

// sourcery: AutoMockable
protocol SendableProtocol: Sendable {
var value: Any { get }
}

protocol NotMockedSendableProtocol: Sendable {}

// sourcery: AutoMockable
protocol SendableSendableProtocol: NotMockedSendableProtocol {
var value: Any { get }
}
24 changes: 24 additions & 0 deletions Templates/Tests/Expected/AutoMockable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,30 @@ class SameShortMethodNamesProtocolMock: SameShortMethodNamesProtocol {
}


}
class SendableProtocolMock: SendableProtocol, @unchecked Sendable {


var value: Any {
get { return underlyingValue }
set(value) { underlyingValue = value }
}
var underlyingValue: (Any)!



}
class SendableSendableProtocolMock: SendableSendableProtocol, @unchecked Sendable {


var value: Any {
get { return underlyingValue }
set(value) { underlyingValue = value }
}
var underlyingValue: (Any)!



}
class SingleOptionalParameterFunctionMock: SingleOptionalParameterFunction {

Expand Down
24 changes: 24 additions & 0 deletions Templates/Tests/Generated/AutoMockable.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,30 @@ class SameShortMethodNamesProtocolMock: SameShortMethodNamesProtocol {
}


}
class SendableProtocolMock: SendableProtocol, @unchecked Sendable {


var value: Any {
get { return underlyingValue }
set(value) { underlyingValue = value }
}
var underlyingValue: (Any)!



}
class SendableSendableProtocolMock: SendableSendableProtocol, @unchecked Sendable {


var value: Any {
get { return underlyingValue }
set(value) { underlyingValue = value }
}
var underlyingValue: (Any)!



}
class SingleOptionalParameterFunctionMock: SingleOptionalParameterFunction {

Expand Down

0 comments on commit 2a26b88

Please sign in to comment.