This MR introduces a correct way of generating mocks for associatedtype in a protocol marked as AutoMockable.
Context
Previously, Sourcery was not generating a compilable mock if a mockable protocol had associatedtypes used as arguments or return values or types for variables in that protocol.
The reason was both that during processing, protocol's generic requirements for associated types were not stored, and that a protocol was not checked if it had associated type or not.
Now, AutoMockable.stencil contains logic to check if there are both associated types and generic requirements for those types in a protocol or not.
Now, if an associated type has a primitive type, and not a protocol, a typealias is injected into the mockable type. When an associated type has a protocol type, then that type is:
migrated to Generic constraint of the generated type
preserving and specifying generic requirements, if any
Resolves: #1333
Description
This MR introduces a correct way of generating mocks for
associatedtype
in a protocol marked asAutoMockable
.Context
Previously, Sourcery was not generating a compilable mock if a mockable protocol had associatedtypes used as arguments or return values or types for variables in that protocol.
The reason was both that during processing,
protocol
's generic requirements for associated types were not stored, and that a protocol was not checked if it had associated type or not.Now,
AutoMockable.stencil
contains logic to check if there are both associated types and generic requirements for those types in a protocol or not. Now, if an associated type has a primitive type, and not a protocol, atypealias
is injected into the mockable type. When an associated type has aprotocol
type, then that type is:Example
Input
Output