We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello 👋 The current AutoMockable.stencil does not properly handle methods methods having closure parameters with more than a single parameter.
AutoMockable.stencil
Example:
// sourcery: AutoMockable protocol MyProtocol { func foo(closureA: @escaping (String, Int) -> Void) }
The generated mock looks like this:
class MyProtocolMock: MyProtocol { //MARK: - foo var fooClosureAEscapingStringIntVoidVoidCallsCount = 0 var fooClosureAEscapingStringIntVoidVoidCalled: Bool { return fooClosureAEscapingStringIntVoidVoidCallsCount > 0 } var fooClosureAEscapingStringIntVoidVoidReceivedClosureA: (((String, Int) -> Void))? var fooClosureAEscapingStringIntVoidVoidReceivedInvocations: [(((String, Int) -> Void))] = [] var fooClosureAEscapingStringIntVoidVoidClosure: ((@escaping (String, Int) -> Void) -> Void)? func foo(closureA: (@escaping (String, Int) -> Void) // <-- there is a missing closing parenthese { fooClosureAEscapingStringIntVoidVoidCallsCount += 1 fooClosureAEscapingStringIntVoidVoidReceivedClosureA = closureA fooClosureAEscapingStringIntVoidVoidReceivedInvocations.append(closureA) fooClosureAEscapingStringIntVoidVoidClosure?(closureA) } }
The solution would be to replace this line with this:
{% macro methodName method %}func {{ method.shortName}}({%- for param in method.parameters %}{% if param.argumentLabel == nil %}_ {% if not param.name == "" %}{{ param.name }}{% else %}arg{{ param.index }}{% endif %}{%elif param.argumentLabel == param.name%}{{ param.name }}{%else%}{{ param.argumentLabel }} {{ param.name }}{% endif %}: {% if param.typeName.isClosure and param.typeName.closure.parameters.count > 1 %}({% endif %}{% call existentialParameterTypeName param.typeName param.isVariadic %}{% if param.typeName.isClosure and param.typeName.closure.parameters.count > 1 %}){% endif %}{% if not forloop.last %}, {% endif %}{% endfor -%}){% endmacro %}
The text was updated successfully, but these errors were encountered:
Fix AutoMockable for closure with multiple parameters
a651efb
Resolves krzysztofzablocki#1356
Successfully merging a pull request may close this issue.
Hello 👋
The current
AutoMockable.stencil
does not properly handle methods methods having closure parameters with more than a single parameter.Example:
The generated mock looks like this:
The solution would be to replace this line with this:
The text was updated successfully, but these errors were encountered: