Code Monkey home page Code Monkey logo

Comments (4)

MatyasKriz avatar MatyasKriz commented on May 25, 2024

Hey, @flopshot. The derivable constraint syntax is not compatible with concrete types, so you can't simply write M1.MatchedType: Int, it complains that Int is neither a protocol nor a class. So then we'd have to compare the type to our type database to check whether the type is a class or protocol.

It's certainly possible to implement this behavior to add even stronger generics support. If you're up for it, please start on the feature/swiftsyntax branch. It's 2.0 release of the library & generator, even though it's not ready for release just yet, but getting close.

Asking about any questions or problems getting the project running is appreciated, as that branch contains a lot of major changes throughout the project, hopefully for the better. 😄 The contributing section in README should still apply, so you can start off there.

from cuckoo.

flopshot avatar flopshot commented on May 25, 2024

Thanks for the response.
In the end, we couldn't simply use $0 as! M1.MatchedType because we may want the stub accept different subclasses in the same test, which wasn't possible with that force cast to the Monomorphic type MatchedType

Also, the compiler error was misleading, because what actually was needed was just to make Request conform to Matchable

We ended up using type erasure to solve our problem and leave the generated code as is

extension Request : Matchable {
    public var matcher: Cuckoo.ParameterMatcher<Request> {
        ParameterMatcher<Request>(matchesFunction: { (request: Request) -> Bool in
            if let productByChoiceIdsRequestRHS = request as? GetProductsByChoiceIdsRequest,
               let productByChoiceIdsRequestLHS = self.self as? GetProductsByChoiceIdsRequest {
                return productByChoiceIdsRequestRHS.choiceIds == productByChoiceIdsRequestLHS.choiceIds
            }

            if let getRecommendationTrayRequestRHS = request as? GetRecommendationTrayRequest,
               let getRecommendationTrayRequestLHS = self.self as? GetRecommendationTrayRequest {
                return getRecommendationTrayRequestLHS.path == getRecommendationTrayRequestRHS.path &&
                getRecommendationTrayRequestLHS.itemsPerPage == getRecommendationTrayRequestRHS.itemsPerPage &&
                getRecommendationTrayRequestLHS.categorySlug == getRecommendationTrayRequestRHS.categorySlug &&
                getRecommendationTrayRequestLHS.contextIds == getRecommendationTrayRequestRHS.contextIds &&
                getRecommendationTrayRequestLHS.excludeChoiceIds == getRecommendationTrayRequestRHS.excludeChoiceIds &&
                getRecommendationTrayRequestLHS.clientFilters.keys.sorted() == getRecommendationTrayRequestRHS.clientFilters.keys.sorted()
            }
 //...
}

Doing this fixed the issue, for using this in our large code base.
Which brings me to my next point, it would be better if the compiler error was more helpful by explicitly saying
Request<T> does not conform to Matchable
instead of
Instance method 'asyncLoadResponse(request:)' requires the types 'GetProductBySlugRequest' and 'Request<Product>' be equivalent
Which I would be happy to make a pull request for, as this was very annoying and led me down a bad path.

If anyone has this problem, the better solutions, though long term, is to use a new class called EquatableRequest<T>, conform it to Equatable and simply inherit any requests you'd like to match in tests to EquatableRequest<T> then you could simple have this single Matchable conformance

extension EquatableRequest : Matchable {
    public var matcher: Cuckoo.ParameterMatcher<Request> {
        ParameterMatcher<Request>(matchesFunction: { (request: Request) -> Bool in
            request == self.self
}

from cuckoo.

flopshot avatar flopshot commented on May 25, 2024

Asking about any questions or problems getting the project running is appreciated, as that branch contains a lot of major changes throughout the project, hopefully for the better. 😄 The contributing section in README should still apply, so you can start off there.

Thanks I will give it a shot next week

from cuckoo.

MatyasKriz avatar MatyasKriz commented on May 25, 2024

2.0 has been released and this hopefully fixed? If not, please reopen. 🙂

from cuckoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.