Comments (11)
Hello @art-divin
@pocketal and I are working on a fix for this issue.
We wonder if it is possible to add isVariadic
information to closure parameter
. We need that information to be able to handle variadic closure parameters.
from sourcery.
Hello @rokridi , @pocketal , this is very nice of you to invest your time into improving Sourcery 🤝
We wonder if it is possible to add isVariadic information to closure parameter
Let's see!
from sourcery.
@rokridi I would like to mention that acceptable implementation would be:
var totoArgsAnyStubWithSomeNameProtocolVoidCallsCount = 0
var totoArgsAnyStubWithSomeNameProtocolVoidCalled: Bool {
return totoArgsAnyStubWithSomeNameProtocolVoidCallsCount > 0
}
var totoArgsAnyStubWithSomeNameProtocolVoidReceivedArgs: ([(any StubWithSomeNameProtocol)])?
var totoArgsAnyStubWithSomeNameProtocolVoidReceivedInvocations: [[(any StubWithSomeNameProtocol)]] = []
var totoArgsAnyStubWithSomeNameProtocolVoidClosure: (([(any StubWithSomeNameProtocol)]) -> Void)?
func toto(args: any StubWithSomeNameProtocol...) {
totoArgsAnyStubWithSomeNameProtocolVoidCallsCount += 1
totoArgsAnyStubWithSomeNameProtocolVoidReceivedArgs = args
totoArgsAnyStubWithSomeNameProtocolVoidReceivedInvocations.append(args)
totoArgsAnyStubWithSomeNameProtocolVoidClosure?(args)
}
i.e. keeping any
and parentheses around the type, as opposed to the expected result in the OP.
from sourcery.
Here is what the Stencil could look like (AutoMockable.txt), however we did not succeed at handling functions having a parameter which is a closure having a variadic parameter.
Example:
func foo(closure: (String...) -> Void)
The corresponding mock:
var func13ParamStringVoidVoidClosure: (((String) -> Void) -> Void)?
func func13(param: (String) -> Void) {
func13ParamStringVoidVoidCallsCount += 1
func13ParamStringVoidVoidClosure?(param)
}
Expected mock:
var func13ParamStringVoidVoidClosure: (((String...) -> Void) -> Void)?
func func13(param: (String...) -> Void) {
func13ParamStringVoidVoidCallsCount += 1
func13ParamStringVoidVoidClosure?(param)
}
from sourcery.
I can pick it up from here, feel free to take a look at other, easy to reproduce bugs that are to be fixed for the next release:
https://github.com/krzysztofzablocki/Sourcery/milestone/6
from sourcery.
a1343ff introduces 👍🏻isVariadic
member to ClosureParameter
. I am adding UTs for it; in the meanwhile, you could take the leverage using that implementation already
Edit: since Swift itself does not support variadic arguments for closures, it is unreasonable to add such implementation detail.
from sourcery.
I am not 100% sure you actually need ClosureParameter.isVariadic
, rather, try simply to modify AutoMockable.stencil
template like here:
{% macro existentialClosureVariableTypeName typeName isVariadic -%}
{%- if typeName|contains:"any " and typeName|contains:"!" -%}
{{ typeName | replace:"any","(any" | replace:"!",")?" }}
{%- elif typeName|contains:"any " and typeName.isClosure and typeName|contains:"?" -%}
{{ typeName | replace:"any","(any" | replace:"?",")?" }}
{%- elif typeName|contains:"any " and typeName|contains:"?" -%}
{{ typeName | replace:"any","(any" | replace:"?",")?" }}
{%- elif typeName|contains:"some " and typeName|contains:"!" -%}
{{ typeName | replace:"some","(any" | replace:"!",")?" }}
{%- elif typeName|contains:"some " and typeName.isClosure and typeName|contains:"?" -%}
{{ typeName | replace:"some","(any" | replace:"?",")?" }}
{%- elif typeName|contains:"some " and typeName|contains:"?" -%}
{{ typeName | replace:"some","(any" | replace:"?",")?" }}
{%- elif isVariadic -%}
- {{ typeName }}...
+ [{{ typeName }}]
{%- else -%}
{{ typeName|replace:"some ","any " }}
{%- endif -%}
{%- endmacro %}
from sourcery.
@art-divin thanks for replying. I updated the issue's description.
The actual stencil has issues. It does not handle closures with existential parameters properly. The macros need to be re-written.
Here is an example of a function having a parameter which is a closure having a variadic parameter:
func foo(closure: (String...) -> Void)
But this case is tricky to handle.
from sourcery.
@rokridi thank you, I see. So the branch I've referred above should support ClosureParameter.isVariadic. Please check
from sourcery.
var func13ParamStringVoidVoidClosure: (((String...) -> Void) -> Void)?
This is not compilable swift - checked yesterday also, to my amusement, variadic is only supported in function signature, does not work with variables.
So, it'd work as:
var func13ParamStringVoidVoidClosure: ((([(String)]) -> Void) -> Void)?
from sourcery.
This PR should fix the issue
from sourcery.
Related Issues (20)
- Malformed generated mocks HOT 1
- Missing bin folder with 2.1.3 HOT 5
- Missing bin folder with 2.1.4 HOT 5
- Homebrew does not include latest version (2.1.4) HOT 3
- The platform of the target `MyApp` (iOS 16.0) is not compatible with `Sourcery (2.1.4)`, which does not support `iOS` HOT 18
- AutoMockable stencil does not support inout parameters HOT 3
- Generated Automockable compilation issue due to malformed generated variable name HOT 2
- [BUG] Generated AutoMockable compilation issues HOT 1
- Windows Support
- Sourcery doesn't properly work when using protocols with primary associated types HOT 2
- Add whitespace trimming configuration for Stencil templates
- [QUESTION] Thread-Safe Mocks HOT 3
- [Bug] Failed to resolve dependencies (SPM issue) HOT 5
- Watch mode only watches sources from last configuration file when passing multiple paths to configuration files using `--config` command line options HOT 3
- Getting generic requirements from methods HOT 1
- Possible to generate asset catalog constants? HOT 1
- Detecting if a variable is an Enum works if enum is declared in the file but doesn't otherwise. HOT 4
- AutoMockable does not generate valid Swift code during method generic requirement parsing HOT 2
- Swift macros and method bodies HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sourcery.