Skip to content
New issue

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

Add support for inout parameter for AutoMockable protocols #1261

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Templates/Templates/AutoMockable.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {{ import }}
{% call accessLevel method.accessLevel %}{% call staticSpecifier method %}var {% call methodClosureName method %}: (({% for param in method.parameters %}{% call existentialClosureVariableTypeName param.typeName param.isVariadic %}{% if not forloop.last %}, {% endif %}{% endfor %}) {% if method.isAsync %}async {% endif %}{% if method.throws %}throws {% endif %}-> {% if method.isInitializer %}Void{% else %}{% call existentialVariableTypeName method.returnTypeName %}{% endif %})?
{% endmacro %}

{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %}
{% macro methodClosureCallParameters method %}{% for param in method.parameters %}{{ '&' if param.typeName.name | hasPrefix:"inout " }}{{ param.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %}

{% macro mockMethod method %}
//MARK: - {{ method.shortName }}
Expand Down
5 changes: 5 additions & 0 deletions Templates/Tests/Context/AutoMockable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,8 @@ protocol SubscriptProtocol {
public protocol ProtocolWithMethodWithGenericParameters {
func execute(param: Result<Int, Error>) -> Result<String, Error>
}

// sourcery: AutoMockable
public protocol ProtocolWithMethodWithInoutParameter {
func execute(param: inout String)
}
5 changes: 5 additions & 0 deletions Templates/Tests/Context_Linux/AutoMockable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,8 @@ protocol SubscriptProtocol {
public protocol ProtocolWithMethodWithGenericParameters {
func execute(param: Result<Int, Error>) -> Result<String, Error>
}

// sourcery: AutoMockable
public protocol ProtocolWithMethodWithInoutParameter {
func execute(param: inout String)
}
27 changes: 26 additions & 1 deletion Templates/Tests/Expected/AutoMockable.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 2.1.4 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable line_length
// swiftlint:disable variable_name
Expand Down Expand Up @@ -1069,6 +1069,31 @@ public class ProtocolWithMethodWithGenericParametersMock: ProtocolWithMethodWith
}


}
public class ProtocolWithMethodWithInoutParameterMock: ProtocolWithMethodWithInoutParameter {

public init() {}



//MARK: - execute

public var executeParamInoutStringVoidCallsCount = 0
public var executeParamInoutStringVoidCalled: Bool {
return executeParamInoutStringVoidCallsCount > 0
}
public var executeParamInoutStringVoidReceivedParam: (String)?
public var executeParamInoutStringVoidReceivedInvocations: [(String)] = []
public var executeParamInoutStringVoidClosure: ((inout String) -> Void)?

public func execute(param: inout String) {
executeParamInoutStringVoidCallsCount += 1
executeParamInoutStringVoidReceivedParam = param
executeParamInoutStringVoidReceivedInvocations.append(param)
executeParamInoutStringVoidClosure?(&param)
}


}
public class ProtocolWithOverridesMock: ProtocolWithOverrides {

Expand Down
Loading