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

matchers: nicer syntax for Type testing #214

Closed
DartBot opened this issue Jun 5, 2015 · 6 comments
Closed

matchers: nicer syntax for Type testing #214

DartBot opened this issue Jun 5, 2015 · 6 comments
Labels
closed-duplicate Closed in favor of an existing report type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="96" height="96"hspace="10"> Issue by seaneagan
Originally opened as dart-lang/sdk#10407


What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

currently it doesn't read as nicely as other matchers:

expect(x, new isInstanceOf<int>());
expect(f, throwsA(new isInstanceOf<ExpectedError>()));

better would be:

expect(x, isA(int));
expect(f, throwsA(isA(ExpectedError)));

or even:

expect(x, int);
expect(f, throwsA(ExpectedError));

I think this is blocked on issue dart-lang/sdk#10406.

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2909286?v=3" align="left" width="48" height="48"hspace="10"> Comment by madsager


cc @sigmundch.
Added Area-Pkg, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2049220?v=3" align="left" width="48" height="48"hspace="10"> Comment by sigmundch


cc @gramster.
Removed Area-Pkg label.
Added Area-unittest label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2762632?v=3" align="left" width="48" height="48"hspace="10"> Comment by gramster


Initially we took this approach because we could not rely on 'is' in dart2js if the type was passed as a parameter. Perhaps there is enough reflection support now to make this work; will have to investigate.

In the meantime, a workaround is to define matcher instances for the types you care about (the library already does this for most exception and error types). E.g.

final is_int = new predicate((x) => x is int, "is an int");

@DartBot DartBot added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) closed-duplicate Closed in favor of an existing report Priority-Medium labels Jun 5, 2015
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2762632?v=3" align="left" width="48" height="48"hspace="10"> Comment by gramster


Added Duplicate label.
Marked as being merged into dart-lang/sdk#8138.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo


Added Pkg-Unittest label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<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.
Added Area-Pkg label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

1 participant