jimmya / sourcery-templates

MIT License
6 stars 6 forks source link

Support generic function parameter #14

Open Schroefdop opened 11 months ago

Schroefdop commented 11 months ago

Function to mock:

    func createFile<T: Encodable>(
        fileName: String,
        in directory: FileStorage.DirectoryType,
        contents object: T?
    ) -> Bool

Output from generator:

    public var invokedCreateFile: Bool { invokedCreateFileCount > 0 }
    public var invokedCreateFileCount = 0
    public var invokedCreateFileParameters: (fileName: String, directory: FileStorage.DirectoryType, object: T?)?
    public var invokedCreateFileParametersList: [(fileName: String, directory: FileStorage.DirectoryType, object: T?)] = []
    public var stubbedCreateFileResult: Bool!
    public var invokedCreateFileExpectation = XCTestExpectation(description: "\(#function) expectation")
    @discardableResult

    public func createFile<T: Encodable>(fileName: String, in directory: FileStorage.DirectoryType, contents object: T?) -> Bool {
        defer { invokedCreateFileExpectation.fulfill() }
        invokedCreateFileCount += 1
        invokedCreateFileParameters = (fileName: fileName, directory: directory, object: object)
        invokedCreateFileParametersList.append((fileName: fileName, directory: directory, object: object))
        return stubbedCreateFileResult
    }

In the invokedCreateFileParameters and invokedCreateFileParametersList the function parameter object is generated with type T?, this should be Encodable

Schroefdop commented 11 months ago

We probably have to check closure parameters too

Schroefdop commented 11 months ago

Also the @discardablerResult annotation is placed in a weird way now that i see it