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

[#1251] Swifty generated variable names + fixed generated mocks compi… #1252

Merged
merged 1 commit into from
Jan 9, 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
8 changes: 6 additions & 2 deletions Templates/Templates/AutoMockable.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import {{ import }}
@testable import {{ import }}
{% endfor %}

{% macro cleanString string %}{{ string | replace:"(","_" | replace:")","" | replace:":","_" | replace:"`","" | replace:" ","_" | replace:"?","_" | replace:"!","_" | replace:",","_" | replace:"->","_" | replace:"@","_" | replace:".","_" | replace:"[","" | replace:"]","" | snakeToCamelCase }}{% endmacro %}
{% macro swiftifyMethodName method %}{% call cleanString method.name | lowerFirstWord %}{% call cleanString method.actualReturnTypeName.name | upperFirstLetter %}{% endmacro %}
{% macro cleanString string %}{{ string | replace:"(","_" | replace:")","" | replace:":","_" | replace:"`","" | replace:" ","_" | replace:"?","_" | replace:"!","_" | replace:",","_" | replace:"->","_" | replace:"@","_" | replace:".","_" | replace:"[","" | replace:"]","" | replace:"<","" | replace:">","" | snakeToCamelCase }}{% endmacro %}
{%- macro swiftifyMethodName method -%}
{%- set cleanMethodName %}{% call cleanString method.name %}{% endset %}
{%- set cleanMethodReturnTypeName %}{% call cleanString method.actualReturnTypeName.name %}{% endset -%}
{{ cleanMethodName | lowerFirstLetter }}{{ cleanMethodReturnTypeName | upperFirstLetter }}
{%- endmacro -%}

{% macro accessLevel level %}{% if level != 'internal' %}{{ level }} {% endif %}{% endmacro %}

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 @@ -235,3 +235,8 @@ protocol SubscriptProtocol {
subscript<T: Hashable>(arg: T) -> T? { get set }
subscript<T>(arg: String) -> T? where T: Cancellable { get throws }
}

// sourcery: AutoMockable
public protocol ProtocolWithMethodWithGenericParameters {
func execute(param: Result<Int, Error>) -> Result<String, Error>
}
29 changes: 29 additions & 0 deletions Templates/Tests/Expected/AutoMockable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1526,4 +1526,33 @@ class VariablesProtocolMock: VariablesProtocol {
var universityMarks: [String: Int] = [:]


}
class ProtocolWithMethodWithGenericParameters: SomeProtocol {




//MARK: - execute

var executeParamResultIntErrorResultStringErrorCallsCount = 0
var executeParamResultIntErrorResultStringErrorCalled: Bool {
return executeParamResultIntErrorResultStringErrorCallsCount > 0
}
var executeParamResultIntErrorResultStringErrorReceivedParam: (Result<Int, Error>)?
var executeParamResultIntErrorResultStringErrorReceivedInvocations: [(Result<Int, Error>)] = []
var executeParamResultIntErrorResultStringErrorReturnValue: Result<String, Error>!
var executeParamResultIntErrorResultStringErrorClosure: ((Result<Int, Error>) -> Result<String, Error>)?

func execute(param: Result<Int, Error>) -> Result<String, Error> {
executeParamResultIntErrorResultStringErrorCallsCount += 1
executeParamResultIntErrorResultStringErrorReceivedParam = param
executeParamResultIntErrorResultStringErrorReceivedInvocations.append(param)
if let executeParamResultIntErrorResultStringErrorClosure = executeParamResultIntErrorResultStringErrorClosure {
return executeParamResultIntErrorResultStringErrorClosure(param)
} else {
return executeParamResultIntErrorResultStringErrorReturnValue
}
}


}
Loading