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 to any keyword for function return type to AutoMockable.stencil #1186

Conversation

paul1893
Copy link
Contributor

@paul1893 paul1893 commented Jul 28, 2023

Context

Following merge of support for any keyword for function parameter type: #1169
We could also add support of any keyword for function return type.

In this PR

I've updated the AutoMockable.stencil to support any keyword for function return type.
As previous PR this is the identified cases for now.

protocol AnyProtocol {
    func q() -> any StubProtocol
    func r() -> (any StubProtocol)?
    func s() -> () -> any StubProtocol
    func t() -> () -> (any StubProtocol)?
    func u() -> (Int, () -> (any StubProtocol)?)
    func v() -> (Int, (() -> any StubProtocol)?)
    func w() -> [(any StubProtocol)?]
    func x() -> [String: (any StubProtocol)?]
    func y() -> (any StubProtocol, (any StubProtocol)?)
    func z() -> any StubProtocol & CustomStringConvertible
}

and the generated output:

class AnyProtocolMock: AnyProtocol {

    //MARK: - q

    var _qCallsCount = 0
    var _qCalled: Bool {
        return _qCallsCount > 0
    }
    var _qReturnValue: (any StubProtocol)!
    var _qClosure: (() -> any StubProtocol)?

    func q() -> any StubProtocol {
        _qCallsCount += 1
        if let _qClosure = _qClosure {
            return _qClosure()
        } else {
            return _qReturnValue
        }
    }

    //MARK: - r

    var _rCallsCount = 0
    var _rCalled: Bool {
        return _rCallsCount > 0
    }
    var _rReturnValue: ((any StubProtocol)?)
    var _rClosure: (() -> (any StubProtocol)?)?

    func r() -> (any StubProtocol)? {
        _rCallsCount += 1
        if let _rClosure = _rClosure {
            return _rClosure()
        } else {
            return _rReturnValue
        }
    }

    //MARK: - s

    var _sCallsCount = 0
    var _sCalled: Bool {
        return _sCallsCount > 0
    }
    var _sReturnValue: (() -> any StubProtocol)!
    var _sClosure: (() -> () -> any StubProtocol)?

    func s() -> () -> any StubProtocol {
        _sCallsCount += 1
        if let _sClosure = _sClosure {
            return _sClosure()
        } else {
            return _sReturnValue
        }
    }

    //MARK: - t

    var _tCallsCount = 0
    var _tCalled: Bool {
        return _tCallsCount > 0
    }
    var _tReturnValue: ((() -> (any StubProtocol)?))!
    var _tClosure: (() -> (() -> (any StubProtocol)?))?

    func t() -> (() -> (any StubProtocol)?) {
        _tCallsCount += 1
        if let _tClosure = _tClosure {
            return _tClosure()
        } else {
            return _tReturnValue
        }
    }

    //MARK: - u

    var _uCallsCount = 0
    var _uCalled: Bool {
        return _uCallsCount > 0
    }
    var _uReturnValue: ((Int, () -> (any StubProtocol)?))!
    var _uClosure: (() -> (Int, () -> (any StubProtocol)?))?

    func u() -> (Int, () -> (any StubProtocol)?) {
        _uCallsCount += 1
        if let _uClosure = _uClosure {
            return _uClosure()
        } else {
            return _uReturnValue
        }
    }

    //MARK: - v

    var _vCallsCount = 0
    var _vCalled: Bool {
        return _vCallsCount > 0
    }
    var _vReturnValue: ((Int, (() -> any StubProtocol)?))!
    var _vClosure: (() -> (Int, (() -> any StubProtocol)?))?

    func v() -> (Int, (() -> any StubProtocol)?) {
        _vCallsCount += 1
        if let _vClosure = _vClosure {
            return _vClosure()
        } else {
            return _vReturnValue
        }
    }

    //MARK: - w

    var _wCallsCount = 0
    var _wCalled: Bool {
        return _wCallsCount > 0
    }
    var _wReturnValue: ([(any StubProtocol)?])!
    var _wClosure: (() -> [(any StubProtocol)?])?

    func w() -> [(any StubProtocol)?] {
        _wCallsCount += 1
        if let _wClosure = _wClosure {
            return _wClosure()
        } else {
            return _wReturnValue
        }
    }

    //MARK: - x

    var _xCallsCount = 0
    var _xCalled: Bool {
        return _xCallsCount > 0
    }
    var _xReturnValue: ([String : (any StubProtocol)?])!
    var _xClosure: (() -> [String : (any StubProtocol)?])?

    func x() -> [String : (any StubProtocol)?] {
        _xCallsCount += 1
        if let _xClosure = _xClosure {
            return _xClosure()
        } else {
            return _xReturnValue
        }
    }

    //MARK: - y

    var _yCallsCount = 0
    var _yCalled: Bool {
        return _yCallsCount > 0
    }
    var _yReturnValue: ((any StubProtocol, (any StubProtocol)?))!
    var _yClosure: (() -> (any StubProtocol, (any StubProtocol)?))?

    func y() -> (any StubProtocol, (any StubProtocol)?) {
        _yCallsCount += 1
        if let _yClosure = _yClosure {
            return _yClosure()
        } else {
            return _yReturnValue
        }
    }

    //MARK: - z

    var _zCallsCount = 0
    var _zCalled: Bool {
        return _zCallsCount > 0
    }
    var _zReturnValue: (any StubProtocol & CustomStringConvertible)!
    var _zClosure: (() -> any StubProtocol & CustomStringConvertible)?

    func z() -> any StubProtocol & CustomStringConvertible {
        _zCallsCount += 1
        if let _zClosure = _zClosure {
            return _zClosure()
        } else {
            return _zReturnValue
        }
    }

}

Let me know if you see more cases to add.

@paul1893 paul1893 force-pushed the tech/existential-type-support branch from 58b0ef6 to f49fd86 Compare July 28, 2023 20:48
@paul1893 paul1893 force-pushed the tech/existential-type-support branch from f49fd86 to 5f6ad94 Compare July 29, 2023 15:59
@art-divin
Copy link
Collaborator

👋🏻 Hey @paul1893 ,

I can see you are working on this one, thank you very much 👍🏻

Could you please rebase so CI tests would pass?

Thank you 🙏🏻

@paul1893
Copy link
Contributor Author

paul1893 commented Jul 29, 2023

Hello @art-divin

Could you please rebase so CI tests would pass?

That's what I was doing following your recent merge 😊🫡

Should be good, let's wait and see what's CI results will be. I also updated Changelog.md as requested by Danger automated comment.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants