-
Notifications
You must be signed in to change notification settings - Fork 214
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
Improve matcher isInstanceOf now that Dart has first class types. #2334
Comments
<img src="https://avatars.githubusercontent.com/u/5479?v=3" align="left" width="48" height="48"hspace="10"> Comment by sethladd Removed Type-Defect label. |
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo Removed Area-UnitTest label. |
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo Removed Pkg-Unittest label. |
<img src="https://avatars.githubusercontent.com/u/248818?v=3" align="left" width="48" height="48"hspace="10"> Comment by vicb This is something I have implemented in Guinness as: bool matches(obj, Map matchState) => see https://github.com/vsavkin/guinness/blob/5f9e291f9c0937a19ab278b0afe7c377bfae25fe/lib/src/common/unittest_backend.dart#L191 for the full Matcher We have started to discuss this with Kevin: https://plus.google.com/u/0/+VictorBerchet/posts/bdDgAfUB9bW?cfem=1 I'm not clear on how this would affect the generated code size:
(I've not really considered JS & its code size for my use case. The reasoning being that if the tests pass with Dart, they should pass after dart2js, if not then this is a dart2js and not your own code issue. The tests are supposed to test your own code, not dart2js - still I'm all for testing with dart2js to help stabilize the tools as long as there is no constraint on my development flow). |
This comment was originally written by greg...@gmail.com I was under the impression that this was already possible: bool isInstance(obj, Type type) => obj is type; "malformed type: line 5 pos 18: using 't' in this context is invalid" I wonder if there is a bug for implementing this - or if it is not possible. In the VM it must just be an int check. Not sure about dart2js. |
This comment was originally written by greg.lo...@gmail.com Erm - "But it looks like this is NOT possible - yet?" |
<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="48" height="48"hspace="10"> Comment by seaneagan In issue dart-lang/sdk#10406 gbracha indicates that this will only be possible via mirrors. Matchers that use mirrors are currently put here: http://www.dartdocs.org/documentation/matcher/0.11.1/index.html#matcher/matcher-mirror_matchers Also this issue is a duplicate of issue #214 which was wrongly merged with issue dart-lang/sdk#8138. |
<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="48" height="48"hspace="10"> Comment by seaneagan Once this is fixed, all the custom |
I believe there are no plans to allow |
Originally opened as dart-lang/sdk#15381
This issue was originally filed by greg...@gmail.com
Current: new isInstanceOf<T>(T t)
New: isInstanceOf2(Type t). // But with a better name.
Consider adding:
throwsType(Type t)
Also worth updating these docs:
"As types are not first class objects in Dart we can only approximate this test by using a generic wrapper class."
"Note that this does not currently work in dart2js; it will match any type, and isNot(new isInstanceof<T>()) will always fail. This is because dart2js currently ignores template type parameters."
https://api.dartlang.org/docs/channels/stable/latest/matcher/isInstanceOf.html
https://www.dartlang.org/articles/writing-unit-tests-for-pub-packages/
The text was updated successfully, but these errors were encountered: