Giter Club home page Giter Club logo

Comments (6)

treastrain avatar treastrain commented on May 24, 2024 2

I hope this feature exists in this OSS! I see three ways to support this:

  1. Add an annotation specifying the object nominal types of the mock
  2. Mocks for that protocol that conform to the Actor automatically become actor
  3. Mocks for that protocol that conform to the another protocol conforming Actor automatically become actor
// 1.
/// @mockable(object: actor)
protocol Hoge: Actor {
    var count: Int { get }
}

///
/// @Generated by Mockolo
///
actor HogeMock: Hoge {
    init() { }
    init(count: Int = 0) {
        self.count = count
    }

    private(set) var countSetCallCount = 0
    var count: Int = 0 { didSet { countSetCallCount += 1 } }
}
// 2.
/// @mockable
protocol Hoge: Actor {
    var count: Int { get }
}

///
/// @Generated by Mockolo
///
actor HogeMock: Hoge {
    init() { }
    init(count: Int = 0) {
        self.count = count
    }

    private(set) var countSetCallCount = 0
    var count: Int = 0 { didSet { countSetCallCount += 1 } }
}
// 3.
/// @mockable
protocol Hoge: Fuga {
    var count: Int { get }
}
protocol Fuga: Actor {
}

///
/// @Generated by Mockolo
///
actor HogeMock: Hoge {
    init() { }
    init(count: Int = 0) {
        self.count = count
    }

    private(set) var countSetCallCount = 0
    var count: Int = 0 { didSet { countSetCallCount += 1 } }
}

I implemented the changes that fulfill "1." and "2." above in my forked branch: master...treastrain:c20f64b140c78b9f05202e661a07c43c15834358 (No test has been added to this yet now.)

However, I have yet to come up with a way to achieve "3." Any suggestions?

from mockolo.

uhooi avatar uhooi commented on May 24, 2024 1

Thanks for the Issue!
I'm waiting for the PR🥺

from mockolo.

uhooi avatar uhooi commented on May 24, 2024 1

@treastrain

I agree with "2." since only actor can conform to the Actor protocol.

I see. I will create a pull request for this part in my spare time.

Thanks, waiting for PR 🙏

"1." may cause mock build errors when marking protocols that are not Actor.

The same could be said here for the already existing annotations typealias, rx, combine, etc. It is the responsibility of the person making this statement, and we do not believe that we should be concerned about mock build errors when marking protocols that are not Actor.

Since you are right, it seems that if "3." cannot be realized by any means, "1." may be adopted.
As for how to realize "3.", the is operator is just an example, and I also thought it could not be solved 😭

Japanese

Actor プロトコルに準拠できるのは actor しかないので、"2." に賛成です。

わかりました。私の余暇の時間でここの部分の pull request を作成してみたいと思います。

ありがとうございます。PR お待ちしております 🙏

"1." は Actor でないプロトコルにマークした場合にモックがビルドエラーになることがあります。

こちらは、すでに存在するアノテーションである typealiasrxcombine などでも同じことが言えるかと思います。> この記述をする人が責任を持つべき事項であり、「Actor でないプロトコルにマークした場合にモックがビルドエラーになること」をこちら側が心配することではないと思っています。

仰る通りなので、どうしても "3." が実現できない場合は "1." を採用してよさそうです。
"3." の実現方法について、 is 演算子は例として挙げただけであり、私も解決できないと思っていました 😭

from mockolo.

uhooi avatar uhooi commented on May 24, 2024

@treastrain Thanks for the suggestion!

I agree with "2." since only actor can conform to the Actor protocol.
Couldn't "3." be achieved using SwiftSyntax and the is operator?
"1." may cause mock build errors when marking protocols that are not Actor.
It seems like it would be better to support only "2." (and "3." if possible) first, what do you think?

Japanese

提案ありがとうございます!

Actor プロトコルに準拠できるのは actor しかないので、"2." に賛成です。
"3." はSwiftSyntaxや is 演算子を使って実現できないでしょうか?

"1." は Actor でないプロトコルにマークした場合にモックがビルドエラーになることがあります。
まずは "2." のみ(できたら "3." も)対応するのがよさそうですがどうでしょうか?

from mockolo.

treastrain avatar treastrain commented on May 24, 2024

@uhooi

Thanks for your response!

The diffs shown in master...treastrain:c20f64b140c78b9f05202e661a07c43c15834358 are a mixture of "1." and "2." but the implementation effort is light < "1." < "2." < heavy.

I agree with "2." since only actor can conform to the Actor protocol.

I see. I will create a pull request for this part in my spare time.

"1." may cause mock build errors when marking protocols that are not Actor.

The same could be said here for the already existing annotations typealias, rx, combine, etc. It is the responsibility of the person making this statement, and we do not believe that we should be concerned about mock build errors when marking protocols that are not Actor.

Couldn't "3." be achieved using SwiftSyntax and the is operator?

My knowledge of SwiftSyntax is lacking, so a solution using it is not immediately obvious.
But as for the is operator, I understand that when this library generates a mock, it does not build and import the source code for the mock generation target, so it can't handle that object directly, so I don't think I can solve it that way.

Japanese ありがとうございます!

master...treastrain:c20f64b140c78b9f05202e661a07c43c15834358 で示した差分は "1." と "2." が混ざったものになっていますが、実装工数は 軽 < "1." < "2." < 重 になっています。

Actor プロトコルに準拠できるのは actor しかないので、"2." に賛成です。

わかりました。私の余暇の時間でここの部分の pull request を作成してみたいと思います。

"1." は Actor でないプロトコルにマークした場合にモックがビルドエラーになることがあります。

こちらは、すでに存在するアノテーションである typealiasrxcombine などでも同じことが言えるかと思います。この記述をする人が責任を持つべき事項であり、「Actor でないプロトコルにマークした場合にモックがビルドエラーになること」をこちら側が心配することではないと思っています。

"3." はSwiftSyntaxや is 演算子を使って実現できないでしょうか?

私の SwiftSyntax に対する知識が足りないため、それを用いた解決方法はすぐには分かりません。
しかし、is 演算子の方については、このライブラリがモックを生成する際に、モック生成対象のソースコードをビルドして import しているわけではないと理解しており、そのオブジェクトを直接取り扱えるわけではないため、その方法ではそれを解決できないと考えます。

from mockolo.

fummicc1 avatar fummicc1 commented on May 24, 2024

Thank you! let me say one opinion from my side. 🙏
I prefer option 1 because we can't take care of @globalActor if we adopt option 2. (if it is not correct please teach me.)
Besides that, option 1 is more flexible and independent on certain swift future change.

oh I am sorry. I found globalActor protocol should be mocked with class.

Besides that, option 1 is more flexible and independent on certain swift future change.

one of example is typealias and AnyActor, DistributedActor.

from mockolo.

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.